Let's have an associative array like this:
var aArray = {};
aArray.id = 'test';
aArray['x1'] = [1,2,3];
aArray['stackoverflow'] = 'What's up?';
aArray['x2'] = [4,5,6];
var keys = [];
for(var key in aArray) {
if (aArray.hasOwnProperty(key)) {
keys.push(key);
}
}
console.log(keys);
Is there any easy/short way how to get array of keys to array variable without loop?
If so, additionally, is possible to apply some regular expression to key list to get just keys that match such pattern (let's say /^x/
) without another loop?