var array = [1,2,3,'4'];
var findIndexOf = (array || []).findIndex((item) => item === '4');
console.log(indexOf4); // 3

var profiles= [
    {
      id: 'id123',
      name: "lin",
      age: 23
    },
    {
      id: 'id456',
      name: "lin2",
      age: 12
    },
    {
      id: 'id678',
      name: "lin3",
      age: 13
    }
];
 
var currentProfile = {
      id: 'id456',
      name: "lin2",
      age: 12
}; 
 
var currentProfileIndex = (profiles|| []).findIndex((profile) => profile.id === currentProfile .id);
 
console.log(currentProfileIndex );

您已经阅读00:00:00欢迎留言评论,喜欢的话就为作者点个赞或者赏颗糖吧! 分享