草庐IT

file_name_array_r

全部标签

javascript - JS (ES6) : Filter array based on nested array attributes

我有一个数组,看起来像这样:constpersons=[{name:"Joe",animals:[{species:"dog",name:"Bolt"},{species:"cat",name:"Billy"},]},{name:"Bob",animals:[{species:"dog",name:"Snoopy"}]}];现在我想根据物种进行过滤。例如:每个养猫的人,都应该返回:constresult=[{name:"Joe",animals:[{species:"dog",name:"Bolt"},{species:"cat",name:"Billy"},]}];我试过这样的fil

javascript - this.name 在 javascript 中返回 undefined

我正在尝试远程创建一个onclick对于每个(以节省打字时间)。这是window.onload()功能:window.onload=function(){divel=document.getElementsByTagName('div');for(varelindivel){divel[el].onmouseover=function(){this.style.textDecoration="underline";};divel[el].onmouseout=function(){this.style.textDecoration="none";};divel[el].onclick=

javascript - Javascript 和 Jquery 中的 array.eq() 与 array[]

访问数组时,什么时候使用.eq()函数比较合适?例如,我有...slides.eq(slidesLength-1).css("z-index",(slidesLength-1));后来我有...for(i=0;i在第一段代码中,如果我不使用.eq()函数,幻灯片将停止运行。但是,无论我是否使用.eq()函数,第二部分似乎都起作用。这是为什么? 最佳答案 slides不是数组。它是一个jQuery对象。.eq()方法返回指定索引处的元素作为jQuery对象。虽然jQuery对象可能不是数组,但它们可以通过具有length属性以及与索引

javascript - array.map 在字符串中连接时自动附加逗号?

我对此处Array.map函数的行为感到有点困惑:vararr=['one','two','three'];varresult='';result+=arr.map(function(elm){returnelm;});//'one,two,three'它如何自动将返回的结果与,连接起来?注意:只有当我将返回的结果连接成一个字符串时才会发生这种情况。 最佳答案 Array.map对您的数组没有任何作用。你基本上做到了这一点''+['one','two','three']调用数组的toString()方法,默认行为是join(',')

javascript - [Vue 警告] : Error in render function: "TypeError: Cannot read property ' first_name' of null"

我有以下Navigation.vue组件:{{user.first_name}}import{mapActions,mapGetters}from'vuex'exportdefault{name:'hello',methods:{...mapActions(['myAccount'])},mounted:function(){if(localStorage.getItem('access_token')){this.myAccount()}},computed:{...mapGetters(['user'])}}此代码返回:[Vuewarn]:Errorinrenderfunction

javascript - 将 Float32Array 转换为 Int16Array

我正在寻找转换Float32Array进入Int16Array.这是我所拥有的(我没有提供数据)。vardata=...;/*newFloat32Array();*/vardataAsInt16Array=newInt16Array(data.length);for(vari=0;i我不相信我做的正确并正在寻找一些方向。 最佳答案 您可以直接从ArrayBuffervardataAsInt16Array=newInt16Array(data.buffer);varf32=newFloat32Array(4);f32[0]=0.1,f

javascript - Array.push 返回推送值?

为什么修改Array.push()以返回推送的对象而不是新数组的长度可能是个坏主意,是否有任何实质性原因?我不知道之前是否有人提出或询问过这个问题;Google搜索只返回了无数与Array.push()当前功能相关的问题。这是此功能的示例实现,请随时更正它:;(function(){var_push=Array.prototype.push;Array.prototype.push=function(){returnthis[_push.apply(this,arguments)-1];}}());然后你就可以做这样的事情了:varsomeArray=[],value="hellowo

javascript - rails : end of file reached

在我的Rails开发环境中工作,一切都很顺利,然后去吃午饭,现在我在浏览器中收到“文件结束”错误。有人知道这是怎么回事吗?这是来自curl的相同响应:$curlhttp://localhost:7000EOFErrorat/=============>endoffilereachedapp/views/application/_javascript.html.slim,line1---------------------------------------------------```ruby>1=javascript_include_tag:application23=yield:j

javascript - 如何使用 Ember.js Array forEach 更改值?

self.resultList.forEach(function(item,index,enumerable){console.log(self.resultList);item.id=11;item.get('id');});像这样的项目:如果item.id=11;像这样的异常:Assertionfailed:YoumustuseEmber.set()toaccessthisproperty(of[objectObject])所以item.get('id')或item.set('id',11)像这样的异常UncaughtTypeError:Object#hasnomethod'get

javascript - Jquery.each() 和 Array.prototype.forEach() 方法的区别

这个问题在这里已经有了答案:jQuery.eachimplementationdiffersfromnativeArray.forEach(3个答案)关闭9年前。Jquery.each()和Array.prototype.forEach()方法之间有什么区别吗,因为array.forEach()方法也可用于循环具有length属性的类数组对象。我看到的唯一区别是参数的放置,它们还有什么不同?Ifoundthis:varobj={one:1,two:2,three:3,four:4,five:5};jQuery.each(obj,function(i,val){$("#"+i).appe