Recently encountered in the project to convert the object array to a key value pair,

Source: Internet
Author: User
First, the key value of the problem:

Key-value pairs ("key = value") strings, which are often used in development;
After each key corresponding to the corresponding value, when the corresponding key is pressed, the corresponding results will be output, then how to use the program to implement it?

Two: for example:

Request: When I get the ID of the address, I want the address name corresponding to the ID to echo to the page.

Three: Specific code:

Like I got the province ID,

Drop the interface to find all the address data.

The data returned by the interface:

Defines an empty object regionobj

Then add the value to this empty pair image:

Regionobj[item.id]=item.name (Item.id is equivalent to the key value = province's ID, Item.name equals value = province's ID corresponds to the province's name field)

Recently encountered in the project to convert the object array to a key value pair,

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.