This question is follow up for, Get the index of a multidimensional array with the value of a given string in javascript
I tried this answer,
var a1 = [["present",["John","Josh","Jay"]],["absent",["May","Mary","Mary Jane"]]],
a2 = [["J",["John","Josh","Jay"]],["M",["May","Mary","Mary Jane"]],["S",["Sally","Sam","Sammy Davis"]]],
getStatus = (a,n) => a.find(e => e[1].indexOf(n) !== -1)[0],
getIndex = (a,n) => a.findIndex(e => e[1].indexOf(n) !== -1);
console.log(getStatus(a1,"Mary"));
console.log(getIndex(a2,"Sammy Davis"));
This is working, but there are issues. What if the given string is not in the array? how to handle that? How to get all the indexes if there are more than one index that have a value of the given string?
For example, In the a1,
var a1 = ["present",["John","Josh","Jay"]],["absent",["May","Josh","Mary Jane"]]]
How to get 0,1? using getIndex()?
a1instead of an object, seems like there is no gain.{ present: ['John, 'Josh'], absent: ['May', 'Mary Jane']}would be easier to work with