Arrays, Objects and Common Methods

Most MERN code is data transformation.

You receive data from APIs, transform it, render it, validate it, or store it.

Important array methods

const nums = [1, 2, 3, 4]

nums.map((n) => n * 2) // [2, 4, 6, 8]
nums.filter((n) => n > 2) // [3, 4]
nums.reduce((sum, n) => sum + n, 0) // 10

Use:

Objects

const user = {
  id: 1,
  name: 'Asha',
}

Common operations:

Object.keys(user)
Object.values(user)
Object.entries(user)

Spread and rest

Copy and update:

const updatedUser = {
  ...user,
  name: 'Ravi',
}

Collect remaining values:

const { id, ...profile } = updatedUser

Interview answer

Arrays and objects are the main data structures used in JavaScript apps. Methods like map, filter, reduce, find, some, and every are used to transform and query arrays. Spread, rest, and destructuring help copy, update, and extract object or array data cleanly.