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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e45a29-43629.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e45a29-43629.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?