-1

I have array containing objects and I want to add a new object to it.

//here is my array    
var countries = [
    { start: 20.2, end: 20.7, country_name: "United States" },
    { start: 20.7, end: 21.2, country_name: "Canada" }
]

//new object to push in this array    
{ start: 23.2, end: 23.7, country_name: "Peru" }
SeinopSys
  • 8,787
  • 10
  • 62
  • 110
  • possible duplicate of [Appending to array](http://stackoverflow.com/questions/351409/appending-to-array) – Peter Tutervai May 30 '15 at 06:57
  • Welcome to SO, please try search for your problem first. It is fairly common and can be found pretty easily. The solution would be to use `push()` of `Array`, well you got your answers now. – Rohit416 May 30 '15 at 07:00

2 Answers2

4

Did you read documentation? I hope you'll try to search first at the next time. Let's make SO free from SUCH trivial questions

countries.push({ start: 23.2, end: 23.7, country_name: "Peru" })
Vasiliy vvscode Vanchuk
  • 7,007
  • 2
  • 21
  • 44
0

use the below code:

var newObj = { start: 23.2, end: 23.7, country_name: "Peru" }
countries.push(newObj);
Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33