
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add new value to an existing array in JavaScript?
To add new value to an existing array, use the JavaScript splice() method.
Example
You can try to run the following code to add new value −
<html> <head> <title>JavaScript Array splice Method</title> </head> <body> <script> var arr = ["orange", "mango", "banana", "sugar", "tea"]; document.write("Original array:"+arr) var newArr = arr.splice(2, 0, "water"); document.write("<br>After adding new element: " + arr ); </script> </body> </html>
Output
Original array:orange,mango,banana,sugar,tea After adding new element: orange,mango,water,banana,sugar,tea
- Related Questions & Answers
- How to add a new column to an existing table using JDBC API?
- How to add new array elements at the beginning of an array in JavaScript?
- How to add items/elements to an existing jagged array in C#?
- How to update field to add value to existing value in MySQL?
- How to add properties and methods to an existing object in JavaScript?
- How to extend an existing JavaScript array with another array?
- How to Create/Add a New Virtual Disk for an Existing Linux Virtual Machine
- How to add columns to an existing MySQL table?
- How to add two arrays into a new array in JavaScript?
- How to add column to an existing table in PostgreSQL?
- How to add a new column at the front of an existing R data frame?
- Add alpha to an existing Matplotlib colormap
- How to add current date to an existing MySQL table?
- How to add/append content to an existing file using Java?
- Add to existing value in MySQL column using CONCAT function?
Advertisements