🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
JS MASTER CLASS /// MASTER THE ENGINE /// BUILD LOGIC /// ASYNC PATTERNS /// JS MASTER CLASS /// MASTER THE ENGINE ///

JavaScript Common Methods & Array Manipulation | JS Tutorial - In-Depth Guide

Comprehensive tutorial on JavaScript Common Methods. Master Array operations (push, pop, splice) and Object enumeration (keys, values). Learn destructive vs non-destructive patterns for modern state management.

Total XP: 0|💻 javascript XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

System Hub

Core logic.

Quick Quiz //

What is the primary advantage discussed here?


🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.

JavaScript arrays and objects come with a rich set of built-in methods for reshaping data — push, pop, shift, unshift, and splice for arrays, and Object.keys()/Object.values() for pulling data out of objects. This lesson covers how each one works, which ones mutate the original data, and how to combine them to transform real data structures.

1JavaScript Common Methods & Array Manipulation | JS Tutorial - In-Depth Guide Part 1

Knowing how to store data is step one. Step two is learning how to manipulate it efficiently using built-in methods.

+
// The Toolset
localhost:3000

Methods

2JavaScript Common Methods & Array Manipulation | JS Tutorial - In-Depth Guide Part 2

Array Mutation: .push() adds an item to the end, while .pop() removes the last item. Think of it like a stack of plates.

+
const tasks = ['Code'];
tasks.push('Test'); // ['Code', 'Test']
tasks.pop(); // ['Code']
localhost:3000

Array Mutation

➕ Push
➖ Pop

3JavaScript Common Methods & Array Manipulation | JS Tutorial - In-Depth Guide Part 3

.unshift() and .shift() work on the beginning of the array. These are slower because JS has to re-index every other item.

+
const queue = ['Alice'];
queue.unshift('Bob'); // ['Bob', 'Alice']
queue.shift(); // ['Alice']
localhost:3000

Front of Array

Shift / Unshift

4JavaScript Common Methods & Array Manipulation | JS Tutorial - In-Depth Guide Part 4

.splice() is the Swiss Army Knife. It can remove, replace, or add items anywhere in the array by specifying an index.

+
const list = ['A', 'B', 'D'];
list.splice(2, 0, 'C'); // At index 2, remove 0, add 'C'
// Result: ['A', 'B', 'C', 'D']
localhost:3000

Splice

✂️ Insert / Remove

5JavaScript Common Methods & Array Manipulation | JS Tutorial - In-Depth Guide Part 5

For Objects, we use 'Static Methods' from the Object constructor. Object.keys() gives you an array of all property names.

+
const user = { name: 'Pascual', role: 'Admin' };
console.log(Object.keys(user)); // ['name', 'role']
localhost:3000

Object.keys

🔑 Names Array

6JavaScript Common Methods & Array Manipulation | JS Tutorial - In-Depth Guide Part 6

Similarly, Object.values() extracts all the data into an array. This is perfect for totaling prices or scores.

+
const prices = { bread: 2, milk: 3 };
const vals = Object.values(prices); // [2, 3]
localhost:3000

Object.values

📦 Data Array

7JavaScript Common Methods & Array Manipulation | JS Tutorial - In-Depth Guide Part 7

Combination: You can use these methods together to transform complex data into exactly what you need.

+
const user = { xp: 100, bonus: 50 };
const total = Object.values(user).reduce((a,b) => a+b);
// total is 150
localhost:3000

Combining Methods

8JavaScript Common Methods & Array Manipulation | JS Tutorial - In-Depth Guide Part 8

Manipulation mastery! You now have the tools to handle real-world data dynamically.

+
<h1>Methods: Mastered</h1>
localhost:3000

Methods Mastered

9JavaScript Common Methods & Array Manipulation | JS Tutorial - In-Depth Guide Part 9

Next, we'll combine everything to master 'Arrays and Loops' for powerful data processing.

+
<h1>Next: Processing</h1>
localhost:3000

On to Processing

10Step-by-Step Breakdown

Knowing how to store data is step one. Step two is learning how to manipulate it efficiently using built-in methods.

Array Mutation: .push() adds an item to the end, while .pop() removes the last item. Think of it like a stack of plates.

.unshift() and .shift() work on the beginning of the array. These are slower because JS has to re-index every other item.

Checkpoint: Which method removes the LAST item from an array?

  • push()
  • pop()
  • shift()

.splice() is the Swiss Army Knife. It can remove, replace, or add items anywhere in the array by specifying an index.

For Objects, we use 'Static Methods' from the Object constructor. Object.keys() gives you an array of all property names.

Similarly, Object.values() extracts all the data into an array. This is perfect for totaling prices or scores.

Checkpoint: Which method extracts all property labels (names) from an object as an array?

  • Object.values()
  • Object.keys()

Combination: You can use these methods together to transform complex data into exactly what you need.

Manipulation mastery! You now have the tools to handle real-world data dynamically.

Checkpoint: If you want to add an item to the BEGINNING of an array, which method do you use?

  • push()
  • unshift()

Next, we'll combine everything to master 'Arrays and Loops' for powerful data processing.

Level Up 🚀

Advanced cheat sheets, SEO tricks, and interview prep for this topic.

Browser Support

ChromeSupported

Fully supported.

FirefoxSupported

Fully supported.

SafariSupported

Fully supported.

EdgeSupported

Fully supported.

Accessibility (A11y)

1Rebuilding a List's DOM on Every Mutation Can Break Screen Reader Announcements

If splice(), push(), or similar array methods trigger a full re-render of a list (rather than an in-place update), assistive technology can lose track of focus or fail to announce which item changed — prefer keyed, targeted DOM updates over full teardown-and-rebuild when a list changes.

// Use stable keys so only changed items re-render

SEO Implications

  • 1

    Mutating Array Methods Can Silently Break Reference Equality Used by Rendering Frameworks

    Methods like push(), pop(), splice(), shift(), and unshift() mutate the array in place rather than returning a new one — frameworks that rely on reference checks to decide whether to re-render (and thus whether to re-crawl updated content) may not detect the change, so content updates can be missed unless you create a new array (e.g. with spread or non-mutating methods) instead.

Best Practices

Know Which Array Methods Mutate and Which Return a Copy

push, pop, shift, unshift, and splice all mutate the original array in place, while methods like map, filter, and slice return a brand-new array. Mixing these up is a common source of bugs when other code still holds a reference to the 'original' array expecting it to be unchanged.

Prefer Object.keys()/Object.values() Over a for...in Loop for Plain Objects

for...in also walks inherited enumerable properties up the prototype chain, which can pull in unexpected keys. Object.keys() and Object.values() only return the object's own properties, giving more predictable results when iterating.

Frequent Bugs

THE BUG

Calling array.splice(index, 1) inside a forEach loop skips over elements.

THE FIX

splice() shifts every subsequent element down by one index immediately, so the loop's next iteration skips the element that just slid into the removed slot. Iterate backwards, or build a new array with filter() instead of mutating the array you're iterating over.

Real-World Examples

Summing an Object's Values for a Shopping Cart Total

An e-commerce cart stored item prices as an object keyed by product ID, and the checkout page needed a single total price without knowing the product IDs in advance.

const cart = { sku101: 19.99, sku203: 34.5, sku307: 9.99 };
const total = Object.values(cart).reduce((sum, price) => sum + price, 0);
// total is 64.48

Interview Prep

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

The Error //

Mutating arrays while iterating over them

// Wrong items.forEach((item, index) => { if (item === 'remove') items.splice(index, 1); }); // Correct const newItems = items.filter(item => item !== 'remove');

The Solution //

Modifying an array's length or contents while looping through it (with a for loop or forEach) can cause elements to be skipped. Use methods like filter() or map() instead.

The Error //

Forgetting to await asynchronous functions

// Wrong const data = fetch('api/data'); console.log(data.json()); // Error // Correct const response = await fetch('api/data'); const data = await response.json();

The Solution //

If a function returns a Promise, you must use 'await' (or .then) to get its resolved value. Otherwise, your variable will hold a Promise object instead of the data.

Lesson Glossary

[01]Push / Pop

Methods to add or remove an item at the end of an array.

Code Preview
arr.push(x) / arr.pop()

[02]Shift / Unshift

Methods to remove or add an item at the beginning of an array.

Code Preview
arr.shift() / arr.unshift(x)

[03]Splice

A powerful method to add/remove items at any index in an array.

Code Preview
arr.splice(idx, qty)

[04]Object.keys()

Returns an array of an object's own enumerable property names.

Code Preview
['name', 'age']

[05]Object.values()

Returns an array of an object's own enumerable property values.

Code Preview
['Pascual', 30]

[06]Mutation

An operation that changes the original data structure rather than returning a new one.

Code Preview
Permanent change

Continue Learning