I want to compare the object with the given array, the object that I am using is mentioned below
var table = { api_key: "1234", data: [{ temperature: 100, humidity: 200 }] };
The array that I used is mention below :
var key = [ '1234', '3456' ]
the code that is used to return the object when the values of array and object api_key is equal mention below
const value = key.filter(val => {
if(table.api_key === val){
console.log({table})
return [table];
}
});
but when I use that code am not getting the return value of that given object. How to return the object when the array value and object api_key values are same
I want to return the same object when condition satisfies example output:
{ api_key: "1234", data: [{ temperature: 100, humidity: 200 }] };
var table = { api_key: "1234", data: [{ temperature: 100, humidity: 200 }] };
var key = [ '1234', '345' ]
const value = key.filter(val => {
if(table.api_key === val){
console.log({table})
return [table];
}
});
console.log({value})
console.log(key.some(v=>table.api_key===v))?console.log(!key.some(v=>table.api_key===v)&&table)?key.includes(table.api_key) ? table : {}