Teniendo en cuenta lo siguiente, ¿cómo puedo obtener el valor de la shape del objeto a una variable?
var data = [ { "Category": "Color", "Options": [ { "Key": "color", "Value": "red" } ] }, { "Category": "Shape", "Options": [ { "Key": "shape", "Value": "circle" } ] } ]; var shape = // want this to be 'circle'si necesita todo el objeto, puede usar find o puede usar reduce para obtener justo lo que necesita o puede obtener todas las opciones con flatMap y luego encontrar la opción que necesita
var data = [ { "Category": "Color", "Options": [ { "Key": "color", "Value": "red" } ] }, { "Category": "Shape", "Options": [ { "Key": "shape", "Value": "circle" } ] } ]; const shape = data.find(d => d.Category === 'Shape') const shapeOption = data.reduce((res, d) => { if(d.Category === 'Shape'){ return d.Options.find(o => o.Key === 'shape').Value } return res }, null) const shapeWithTransformations = data.flatMap(d => d.Options).find((o) => o.Key === 'shape').Value console.log(shape) console.log(shapeOption) console.log(shapeWithTransformations)En tu caso será
var data = [ { "Category": "Color", "Options": [ { "Key": "color", "Value": "red" } ] }, { "Category": "Shape", "Options": [ { "Key": "shape", "Value": "circle" } ] } ]; const shape = data[1]['Options'][0]['Value']; console.log(shape);Pero su estructura es demasiado complicada, si tiene control sobre ella, entonces debería ser algo como
const data = { 'Color': { 'Key': 'color', 'Value': 'red' }, 'Shape': { 'Key': 'shape', 'Value': 'circle' } }; const shape = data['Shape']['Value']; console.log(shape);