The array adds new properties to the old array of properties mentioned in the new array to go

Source: Internet
Author: User

1. Add a new property to the array:

1.1: Build an array first:

var oldarr=[{name: ' li '},{name: ' Hi '},{name: ' Us '}

1.2: Add a new property to this array in the method:

function Looppushobj (Oldarr) {let arr=[]; if (oldarr&&oldarr.length>0) {    for (var in oldarr) {          var tempobj = {};         = Oldarr[i];        tempobj[' sex ' = ' male ';        Arr.push (tempobj);    }} return     arr;}

1.3: Build good one new array, push in:

var newArr = looppushobj (Oldarr)
2. The properties of the old array refer to the new array:

2.2 The method of the second step is different, the principle is the same:

function Looppushobj (Oldarr) {let arr=[]; if (oldarr&&oldarr.length>0) {    for (var in oldarr) {          var tempobj = {};         = I.name;        Arr.push (tempobj);    }} return     arr;}

The array adds new properties to the old array of properties mentioned in the new array to go

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.