jquery - Object insert issue in JavaScript array -
this question has answer here:
- how insert item array @ specific index? 10 answers
i have javascript array below:
[ {type: 'text', name: 'title', id: 'title', placeholder: 'type here'}, {type: 'textarea', name: 'description', id: 'description', placeholder: 'type here'} ] now want inset {type: 'text', name: 'age', id: 'age', placeholder: 'type here'} after first object. final result set looks like:
[ {type: 'text', name: 'title', id: 'title', placeholder: 'type here'}, {type: 'text', name: 'age', id: 'age', placeholder: 'type here'} {type: 'textarea', name: 'description', id: 'description', placeholder: 'type here'} ] i want in plain javascript or jquery!
like this:
var = [ {type: 'text', name: 'title', id: 'title', placeholder: 'type here'}, {type: 'textarea', name: 'description', id: 'description', placeholder: 'type here'} ] var b= {type: 'text', name: 'age', id: 'age', placeholder: 'type here'} a.splice(1,0,b); console.log(a)
Comments
Post a Comment