How does js get where the element first appears in the array?

at first I thought of indexOf (), but the usage on the Internet is an one-dimensional array. What if the array contains multiple objects?

array:[
    {
        id:1,
        name:"A"
    },
    {
        id:2,
        name:"B"
    },
    {
        id:3,
        name:"B"
    }
]
console.log(this.array.id.indexOf(2)); //
Apr.01,2021

your array is not a two-dimensional array, it is an array object, and it still belongs to an one-dimensional array

you can use findIndex to find subscripts

var fid = 2
array.findIndex(i=>i.id==fid);//1

just modify your last sentence

console.log(this.array.map(o=>o.id).indexOf(2))

console.log (this.array.indexOf ({id:2,name:'B'}));


read more documents

Menu