欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JavaScript 根据对象某属性获得其在数组中的index

程序员文章站 2022-06-28 18:24:12
var arr = new Array({"name": "wxx", "age": 2}, {"name": "wyw", "age": 6});var index = arr.findIndex(function(item) { return item.name "wyw";});console ......
var arr = new Array({"name": "wxx", "age": 2}, {"name": "wyw", "age": 6});

var index = arr.findIndex(function(item) {
return item.name === "wyw";
});
console.log(index);