React by Patrik

Extending Arrays with Attributes in JavaScript

Overview: In many situations, you may need to store more than just simple values in an array. Extending arrays to include attributes such as gender, language, or other metadata can add significant flexibility to your data. This Snipp shows how to structure an array to include such attributes.

Implementation:

const namesWithAttributes = [
  { name: "Norbert", gender: "male", language: "German" },
  { name: "Manuela", gender: "female", language: "Spanish" },
  { name: "Saskia", gender: "female", language: "Dutch" },
  { name: "Henrik", gender: "male", language: "Swedish" },
  { name: "Claus", gender: "male", language: "Danish" },
];

In this example, each item in the array is an object containing a name, gender, and language. This structure allows you to filter and manipulate the data based on multiple attributes easily.

JavaScript
Array

Comments