I'm trying to get a value from multidimensional object with JavaScript. I've tried with .filter
, but it appears to be working on arrays only. Also, I almost did it with UnderscoreJS
's _where
, but it works with non-multidimensional objects only. Is it even possible, or I have to reconstruct my object? I'll be grateful for any hint... Please help :'(
Code (https://jsfiddle.net/ob58fye2/):
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var configurators = JSON.parse('{"ConfiguredItems":{"OtapiConfiguredItem":[{"Id":"3667395302656","Quantity":"2981","Configurators":{"ValuedConfigurator":[{"@attributes":{"Pid":"1627207","Vid":"3224419"}},{"@attributes":{"Pid":"20509","Vid":"28383"}}]}},{"Id":"3667395302655","Quantity":"4145","Configurators":{"ValuedConfigurator":[{"@attributes":{"Pid":"1627207","Vid":"129819"}},{"@attributes":{"Pid":"20509","Vid":"28383"}}]}},{"Id":"3667395302654","Quantity":"0","Configurators":{"ValuedConfigurator":[{"@attributes":{"Pid":"1627207","Vid":"80557"}},{"@attributes":{"Pid":"20509","Vid":"28383"}}]}}]}}');
function FindConfigurator(pid, vid) {
var id = null;
//
console.log(configurators); // Returns the configurators.
console.log(id); // Should return `3667395302656`.
}
FindConfigurator(1627207, 3224419);
</script>
</head>
</html>