var array = [1,2,3,'4'];
var indexOf4 = (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 );