如何在JavaScript数组中选择数据作为PHP?
var myarray = [
{name:"Nita",id:"001"},
{name:"Lyda",id:"002"},
{name:"Lika",id:"003"}
];
select(name,id).from(myarray).where(name like %L%);
如何选择这样的数据?
答案 0 :(得分:0)
也许您可以结合使用filter
(带有字符串match
)和map
:
var myarray = [{name:"Nita",id:"001",age:52},
{name:"Lyda",id:"002",age:34},
{name:"Lika",id:"003",age:20}];
// select(name,id).from(myarray).where(name like %L%);
var res = myarray
.filter(d => d.name.match('L'))
.map(({name, id}) => ({name, id}));
console.log(res);
答案 1 :(得分:0)