jQuery will not help you with what you want to achieve.
You can affect the wanted property thanks to the following: yourArray['yourProperty'] = 'yourValue';
.
const arr = [];
arr['name'] = true;
arr['price'] = true;
arr['stock'] = false;
// Access properties like:
console.log(arr['name']);
if (arr['name'] === true) {
console.log('name is true');
}
However, be aware that the length of you array will stay at 0. So you will not be able to loop through it with a simple for
statement neither a for...of
statement.
Note: I suggest you to use objects instead, as arrays are not made to have string properties.
Please, read the link @GalAbra give us in the comments for further details.
const obj = {
name: true,
price: true,
stock: false
};
// Access properties like:
console.log(obj.name);
if (obj.name === true) {
console.log('name is true');
}