草庐IT

filter-name

全部标签

Javascript 数组 filter() 与 bind()

我正在使用filter()数组助手来遍历数组中的一些对象。我的想法是创建一个动态过滤函数以使用bind()遍历数组中的对象,但bind中的参数的使用方式与我预期的不同。这是代码:varproducts=[{name:"lettuce",type:"vegetable"},{name:"apple",type:"fruit"},{name:"carrot",type:"vegetable"},{name:"orange",type:"fruit"}];//thisisthefunctionusedinfilter()functionfilterProducts(cat,product){

Javascript Array.prototype.filter 意外输出

背景最近在面试,有人给我做了个测试:vararray=[1,2,3];array[10]=10;alert(array.filter(n=>n===undefined));我相信这会警告一个数组有7xundefined,或者这些行中的某些内容。但是,它输出一个空数组,如长度为0的数组。问题对我来说,这是令人困惑的。谁能帮我解释为什么会这样? 最佳答案 不访问已删除或未初始化(在稀疏数组上)的项目。Array#forEachDescriptionforEach()executestheprovidedcallbackonceforea

javascript - 新 ECMA5 Javascript 标准中的 argument.callee.name 替代方案

这个问题在这里已经有了答案:Alternativetoarguments.callee(2个答案)关闭8年前。我正在努力将一些旧代码移植到“严格模式”,ECMA5标准中的argument.callee和类似的argument.caller等有哪些替代方案?添加信息:我没有说明为什么我需要argument.caller/callee。我正在移植的代码正在使用assert.ok(elemNode,arguments.callee.name+":Entity-"+entityId+"hasbeenfound");如果它是简单的递归,我可以使用functionname(){...functio

javascript - Bootstrap table Js 中的 data-sort-name 是如何工作的?

我正在使用以下库:http://bootstrap-table.wenzhixin.net.cn/documentation/我将json对象加载到这个工作正常的表中,但现在问题来了。我希望能够对列进行排序。我的Json布局如下:[{"Total":12345.56,"Name":"Monkey1","TotalFormatted":"$12.345,56"},{"Total":13345.56,"Name":"Monkey3","TotalFormatted":"$13.345,56"},{"Total":11345.56,"Name":"Monkey2","TotalFormatt

javascript - 为什么 JavaScript 不允许在函数上分配属性 "name"?

有关Firefox和Chrome控制台中发生的情况,请参见下文:>varf=function(){}undefined>f.name='f'"f">f.name"">f.id=11>f.id1为什么f.name='f'是空操作? 最佳答案 可能取决于实现。在某些实现中,函数对象的name属性被用作函数的名称(如果有的话)。在这些情况下,这可能是只读的。这是一个非标准功能。例如:varfoo=functionbar(){};alert(foo.name);//willgive"bar"insomecases.在Firefox和Chro

javascript - react native : @providesModule declaration with the same name across two different files

我们有两个repos,它们都有react-native作为依赖项;一个是实际的RN应用程序,另一个是UI包,其中包含许多自定义的react-native组件。当我使用RN应用程序符号链接(symboliclink)(使用npm链接)UI包并尝试启动js服务器时,它抛出以下错误:此错误是由两个不同文件中具有相同名称的@providesModule声明引起的。这似乎是因为它在UI包的react-native副本中获取相同的RN文件。我知道watchman不使用符号链接(symboliclink)存在问题,但我认为这是不同的-与有两个react-native模块有关。请问有人知道解决这个问题

javascript - "first-name"如何成为 JavaScript 中的保留字?

注意:此问题与DougCrockford撰写的“JavaScript:TheGoodParts”一书有关。当我阅读关于对象的一章时,我遇到了如下声明:Thequotesaroundaproperty'snameinanobjectliteralareoptionalifthenamewouldbealegalJavaScriptnameandnotareservedword.Soquotesarerequiredaround"first-name",butareoptionalaround"first_name".下面是书中提供的一个对象字面量的例子:varstooge={"first

javascript - lodash/js : Filtering values within an object based on regular expressions and getting the highest by comparison

对于下面的json[{"index":"xyz",...},{"index":"abc1234",...},{"index":"xyz",...},{"index":"abc5678",...}...我想分别过滤掉abc值和xyz值。我尝试了以下方法来获取值varx=_.filter(jsonData,function(o){return/abc/i.test(o.index);});它可以提供过滤后的输出。现在我想获得最高的abc值,如果有值abc123,abc444,abc999那么代码应该返回abc999。我可以使用lodash再次循环,但这是否可以在一次调用中完成-在同一个过滤

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=