If your data is in JSON format and stored as a string, you can easily convert it to an object in JavaScript using the built-in JSON.parse method. In this object, `Jar1` and `Jar2` will represent properties. To find the property that contains the `class3` value, you can iterate through all entries in the object until you locate the desired one. Retrieve all entries of an object with the standard JavaScript method Object.entries, which gives you access to all property names and values within the object. By utilizing the Object.keys method, you can search for keys within the value object to ascertain if the object includes the `class3` property.
Below is an example demonstrating this approach:
const classItem = 'class3';
const parsedJsonObject = JSON.parse(`{
"Jar1": { "class1": ["method1", "method2"], "class2": ["method2", "method3"] },
"Jar2": { "class3": ["method1", "method2"], "class4": ["method2", "method3"] }
}`)
const [jarPropertyName, _] = Object.entries(parsedJsonObject).find(([_ ,jarObject]) => Object.keys(jarObject).includes(classItem));
console.log(jarPropertyName);
You can also check out this StackBlitz link for a working example.