I am struggling to figure out how to locate the key in my json array.
When I try to find the key using a function parameter, it does not seem to work.
This is a snippet of my json data:
...
{
"product": [
{
"title": "myProductTitle",
...
The following code successfully returns an object:
function retrieveKey(json, key)
{
console.log(key); // should be "myProductTitle"
let obj = json.product.find(item => item.title === "myProductTitle");
return obj;
}
However, this code returns an empty object:
function retrieveKey(json, key)
{
console.log(key); // should be "myProductTitle"
let obj = json.product.find(item => item.title === key);
return obj;
}
What is the correct way to accomplish this task?