I'm trying to findIndex of an object in an array containing multiple objects. I've been struggling with this for a while and have simplified it to what you see and still cannot get it. Please let me know what will work so that I can get the "input" object's string from matchBetween("string1");
matchBetween("string1");
matchBetween = function (result) {
let params = [
{ param: "string1", input: "inputstring1"},
{ param: "string2", input: "inputstring2"}
];
console.log(result, params, params.param ); //Output: "string1", (2)[{...}, {...
let location = params.findIndex (x => Object.is(result, x));
console.log(location); //outputs -1
return params[location].input // 'Cannot read property 'input' of undefined'
};
I've attempted multiple things, but I feel like it's an easy fix and I'm just missing it. THank you in advance!
x=>x.param == resultinsteadparams.paramwill always be undefined as that's not how arrays of objects works