惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
腾讯CDC
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
量子位
博客园 - 聂微东
Jina AI
Jina AI
小众软件
小众软件
The Cloudflare Blog
有赞技术团队
有赞技术团队
V
V2EX
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
B
Blog
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
宝玉的分享
宝玉的分享
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
N
Netflix TechBlog - Medium
I
InfoQ
J
Java Code Geeks
S
SegmentFault 最新的问题
V
Visual Studio Blog
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
D
DataBreaches.Net
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
B
Blog RSS Feed
S
Schneier on Security
Webroot Blog
Webroot Blog
P
Proofpoint News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
Project Zero
Project Zero
Scott Helme
Scott Helme
C
CERT Recently Published Vulnerability Notes
P
Privacy International News Feed
T
The Exploit Database - CXSecurity.com
D
Darknet – Hacking Tools, Hacker News & Cyber Security

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
JavaScript Arrays Methods - Part 1
Annapoorani Kadhiravan · 2026-06-26 · via DEV Community

What is an Array?

An Array is a special object in JavaScript used to store multiple values in a single variable.

Instead of creating separate variables,

let student1 = "John";
let student2 = "David";
let student3 = "Alex";

we can use an array:

let students = ["John", "David", "Alex"];

Each value inside the array is called an element, and every element has an index starting from 0.

Index :   0        1        2
        -------------------------
Array : | John | David | Alex |
        -------------------------


1. Array length

Definition

The length property returns the total number of elements present in an array.

It is not a function. It is a property of an array object.

It is also writable, meaning you can change the length to increase or decrease the array size.


Syntax

array.length

To modify the array length:

array.length = newLength;


Parameters

None.


Returns

Returns a number representing the total number of elements in the array.


Internal Working

Consider this array:

let fruits = ["Apple", "Orange", "Mango"];

Memory representation:

Index

0 → Apple
1 → Orange
2 → Mango

length = 3

When JavaScript creates the array, it internally stores a special property:

{
  0: "Apple",
  1: "Orange",
  2: "Mango",
  length: 3
}

Whenever you access:

fruits.length

JavaScript simply returns the value stored in the length property.

It does not count the elements every time.

This makes length very fast.


Example 1

let fruits = ["Apple", "Orange", "Banana"];

console.log(fruits.length);

Output

3


Example 2 - Updating Length

let numbers = [10,20,30,40];

numbers.length = 2;

console.log(numbers);

Output

[10,20]

JavaScript removes the remaining elements.


Example 3 - Increasing Length

let colors = ["Red","Blue"];

colors.length = 5;

console.log(colors);

Output

["Red","Blue", empty × 3]

The new positions become empty slots.


Real-Time Example

Imagine an E-commerce Shopping Cart.

let cart = ["Laptop", "Mouse", "Keyboard"];

console.log("Total Items:", cart.length);

Output

Total Items: 3

Amazon and Flipkart use similar logic to display:

Cart (3 Items)


Common Mistake

let arr = [1,2,3];

console.log(arr.length());

Output

TypeError

Why?

Because length is a property, not a method.

Correct:

arr.length


Best Practices

✔ Use length inside loops.

for(let i=0;i<arr.length;i++){
    console.log(arr[i]);
}


2. Array toString()

Definition

The toString() method converts an array into a comma-separated string.

The original array is not modified.


Syntax

array.toString()


Parameters

None.


Returns

Returns a string.


Internal Working

Suppose

let fruits = ["Apple","Orange","Banana"];

Internally JavaScript joins every element using commas.

Apple + "," +
Orange + "," +
Banana

Result

Apple,Orange,Banana


Example

let fruits = ["Apple","Orange","Banana"];

let result = fruits.toString();

console.log(result);

Output

Apple,Orange,Banana


Example with Numbers

let numbers = [10,20,30];

console.log(numbers.toString());

Output

10,20,30


Real-Time Example

Sending array data through an API.

let selectedItems = ["Laptop","Mouse","Keyboard"];

let apiData = selectedItems.toString();

console.log(apiData);

Output

Laptop,Mouse,Keyboard


Common Mistake

Many developers think it returns an array.

Wrong.

let result = [1,2,3].toString();

console.log(typeof result);

Output

string


Best Practice

Use join() when you need a custom separator.


3. Array at()

Definition

The at() method returns the element at a specified index.

Unlike bracket notation ([]), it also supports negative indexing.


Syntax

array.at(index)


Parameters

Parameter Description
index Position of element

Returns

Returns the element.

Returns undefined if the index is invalid.


Internal Working

Example

let arr = ["A","B","C","D"];

0 → A
1 → B
2 → C
3 → D

When

arr.at(2)

JavaScript returns

C

When

arr.at(-1)

JavaScript converts

length + (-1)

4 + (-1)

=3

Returns

D


Example

let fruits = ["Apple","Orange","Banana"];

console.log(fruits.at(1));

Output

Orange


Negative Index

let fruits = ["Apple","Orange","Banana"];

console.log(fruits.at(-1));

Output

Banana


Real-Time Example

Latest Notification

let notifications = [
    "Order Placed",
    "Order Shipped",
    "Delivered"
];

console.log(notifications.at(-1));

Output

Delivered


Common Mistake

arr[-1]

Output

undefined

Correct

arr.at(-1)


4. Array join()

Definition

The join() method combines all array elements into a single string using a specified separator.

Unlike toString(), you can choose the separator.

The original array is not modified.


Syntax

array.join(separator)


Parameters

Parameter Description
separator (optional) String inserted between elements. Default is ",".

Returns

A string containing all array elements joined together.


Internal Working

let fruits = ["Apple", "Orange", "Banana"];

If you call:

fruits.join(" - ");

JavaScript internally performs:

"Apple" + " - " +
"Orange" + " - " +
"Banana"

Result:

Apple - Orange - Banana


Example 1

let fruits = ["Apple", "Orange", "Banana"];

console.log(fruits.join());

Output

Apple,Orange,Banana


Example 2

let fruits = ["Apple", "Orange", "Banana"];

console.log(fruits.join(" | "));

Output

Apple | Orange | Banana


Real-Time Example

Suppose a user selects multiple skills in a job portal.

let skills = ["JavaScript", "React", "Node.js"];

let profile = skills.join(", ");

console.log(profile);

Output

JavaScript, React, Node.js

This is commonly used to display selected skills on a profile page.


Common Mistake

Developers sometimes expect join() to return an array.

let result = ["A", "B"].join("-");

console.log(typeof result);

Output

string


What is the difference between join() and toString()?

join() toString()
Allows a custom separator Always uses a comma
Returns a string Returns a string
Does not modify the array Does not modify the array

Best Practices

✔ Use join() whenever you need a specific separator, such as spaces, hyphens, or pipes.


5. Array pop()

Definition

The pop() method removes the last element from an array and returns that removed element.

The original array is modified.


Syntax

array.pop()


Parameters

None.


Returns

Returns the removed element.

If the array is empty, it returns undefined.


Internal Working

Consider:

let fruits = ["Apple", "Orange", "Banana"];

Memory before pop():

Index

0 → Apple
1 → Orange
2 → Banana
length = 3

When you call:

fruits.pop();

JavaScript:

  1. Retrieves the last element (Banana).
  2. Removes it from the array.
  3. Decreases the length property by 1.
  4. Returns the removed element.

Memory after:

Index

0 → Apple
1 → Orange
length = 2


Example

let fruits = ["Apple", "Orange", "Banana"];

let removed = fruits.pop();

console.log(removed);
console.log(fruits);

Output

Banana
["Apple", "Orange"]


Real-Time Example

Imagine a browser's recent tabs list.

let recentTabs = ["Home", "Products", "Cart"];

let closedTab = recentTabs.pop();

console.log("Closed:", closedTab);
console.log(recentTabs);

Output

Closed: Cart
["Home", "Products"]


Common Mistake

let arr = [];

console.log(arr.pop());

Output

undefined

Always check if the array has elements before calling pop() if your logic depends on a removed value.


1. Array.isArray()

Note: isArray() is not an array method. It is a static method of the Array object.


Definition

The Array.isArray() method checks whether a given value is an array.

It returns:

  • true → if the value is an array
  • false → otherwise

Why do we need it?

In JavaScript:

typeof []

returns

"object"

So we cannot use typeof to determine whether a variable is an array.

Instead, JavaScript provides:

Array.isArray()


Syntax

Array.isArray(value)


Parameter

Parameter Description
value The value to check

Returns

Boolean

true
false


Internal Working

Suppose

let numbers = [10,20,30];

Internally JavaScript checks the object's internal type.

numbers

↓

Object

↓

Internal Array Type?

↓

Yes

↓

Return true

If

let person = {
    name: "John"
};

then

person

↓

Object

↓

Internal Array Type?

↓

No

↓

Return false


Example 1

let numbers = [10,20,30];

console.log(Array.isArray(numbers));

Output

true


Example 2

let student = {
    name: "David"
};

console.log(Array.isArray(student));

Output

false


Example 3

console.log(Array.isArray("JavaScript"));

console.log(Array.isArray(100));

console.log(Array.isArray(true));

Output

false
false
false


Real-Time Example

Suppose an API returns data.

function displayProducts(products){

    if(Array.isArray(products)){
        console.log("Displaying products...");
    }else{
        console.log("Invalid Data");
    }

}

displayProducts(["Laptop","Mouse"]);

Output

Displaying products...

Without checking, your application could crash when trying to iterate over non-array data.


Common Mistake

Wrong

typeof []

Output

object

Correct

Array.isArray([])

Output

true


Best Practice

Always validate API responses before looping.

if(Array.isArray(data)){
    data.forEach(item=>console.log(item));
}


2. delete Operator (Array delete)

Important: delete is not an array method. It is a JavaScript operator.


Definition

The delete operator removes an element from an array without changing the array length.

Instead of removing the index, it creates an empty slot (hole).


Syntax

delete array[index]


Parameter

Parameter Description
index Position of element

Returns

Returns

true

if deletion succeeds.


Internal Working

Array

let fruits = [
"Apple",
"Orange",
"Banana"
];

Memory

0 → Apple

1 → Orange

2 → Banana

length = 3

After

delete fruits[1];

Memory

0 → Apple

1 → Empty

2 → Banana

length = 3

Notice

Length remains

3


Example

let fruits = ["Apple","Orange","Banana"];

delete fruits[1];

console.log(fruits);

console.log(fruits.length);

Output

[
'Apple',
empty,
'Banana'
]

3


Access Deleted Value

console.log(fruits[1]);

Output

undefined


Real-Time Example

Suppose an employee leaves.

let employees = [
"John",
"David",
"Alex"
];

delete employees[1];

console.log(employees);

Instead of shifting everyone,

JavaScript leaves an empty position.

Usually, this is not what we want.


3. Array.concat()

Definition

The concat() method merges two or more arrays into a new array.

The original arrays remain unchanged.


Syntax

array1.concat(array2)

array1.concat(array2,array3,...)


Parameters

One or more arrays or values.


Returns

Returns a new merged array.


Internal Working

let a=[1,2];

let b=[3,4];

JavaScript creates

New Array

↓

Copy a

↓

Append b

↓

Return New Array

Original arrays stay unchanged.


Example

let frontend=["HTML","CSS"];

let backend=["Node","Express"];

let fullstack=frontend.concat(backend);

console.log(fullstack);

Output

["HTML","CSS","Node","Express"]


Multiple Arrays

let a=[1];

let b=[2];

let c=[3];

console.log(a.concat(b,c));

Output

[1,2,3]


Real-Time Example

Suppose a school stores students section-wise.

let sectionA=["John","David"];

let sectionB=["Alex","Sam"];

let students=sectionA.concat(sectionB);

console.log(students);

Output

["John","David","Alex","Sam"]


Common Mistake

Developers think

a.concat(b);

changes a.

Wrong.

It returns a new array.

Correct

let newArray = a.concat(b);


4. Array.copyWithin()

Definition

The copyWithin() method copies part of an array to another position within the same array.

It overwrites existing elements and modifies the original array.


Syntax

array.copyWithin(target)
array.copyWithin(target, start)
array.copyWithin(target, start, end)


Parameters

Parameter Description
target Index where copied values will be placed
start Start copying from this index
end (optional) Stop copying before this index

Returns

The modified original array.


Internal Working

let arr = [10,20,30,40,50];

Calling

arr.copyWithin(0,3);

copies elements from index 3 onward (40,50) to index 0.

Result

[40,50,30,40,50]


Example

let numbers=[10,20,30,40,50];

numbers.copyWithin(0,3);

console.log(numbers);

Output

[40,50,30,40,50]


Real-Time Example

Suppose you maintain a fixed-size buffer for sensor readings and want to overwrite old values with recent ones.

let readings=[10,20,30,40,50];

readings.copyWithin(0,2);

console.log(readings);

Output

[30,40,50,40,50]


Best Practice

Use copyWithin() only when you intentionally want to overwrite elements in the same array.


References:
https://www.w3schools.com/js/js_array_methods.asp