What's the best way to query an array in javascript to get just the items from it I want?

后端 未结 7 1172
悲哀的现实
悲哀的现实 2020-12-13 18:48

I have an array like this (with just over 3000 objects instead of the 3 here):

items = [{name:\'charlie\', age:\'16\'}, {name:\'ben\', age:\'18\'}, {name:\'s         


        
7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 19:15

    No matter which method you choose (items.filter or any "query language" for json), a for loop is inevitable.

    If performance is a concern, I would recommend you to use pure javascript instead of libraries like jQuery which will add overheads to the whole processing as is evident here.

    Thus, your code would look like:

    var newArray = [];
    for(var i=0;i

提交回复
热议问题