If you want to retrieve all the keys from an array, you can use the following command: Object.keys(arrayName);
To specifically extract the keys that are not numerical and create a separate object containing these keys along with their corresponding values, you can utilize the code snippet below:
let nonNumericalKeys = {};
let keysFromArray = Object.keys(arrayName);
for (let i = 0; i < keysFromArray.length; i++) {
if(isNaN(keysFromArray[i]) === true) {
nonNumericalKeys['i'] = arrayName[i];
}
}
You will now have an object named nonNumericalKeys which stores all properties of the array referenced as arrayName
, excluding any numerical properties.