Вопрос

I have an JavaScript object looking like this:

Object {@attributes: Object,…}

So how can I access the @attributes-Object?

Это было полезно?

Решение

parent["@attributes"], thus:

var parent = { "@attributes" : someObj} ;
console.log(parent["@attributes"]);

In JS, all property names can be used as named array elements. Most (i.e. those without spaces etc) can be used as bare property names.

var foo = { bar: 1};

foo.bar = 2 // or
foo["bar"] = 2

Другие советы

You can use the bracket notation:

var myObject = { '@attributes': 'foo' };
var result = myObject['@attributes']; // foo
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top