How can I traverse the following array in HTML? I tried many methods and reported errors.

Source: Internet
Author: User
{Code...} now only wants to traverse the array bigimg
Array(    [bigimg] => Array        (            [0] => Array                (                    [id] => 2                    [imgtitle] => abc                    [imgintro] => asdasd                    [filename] => sda.jpg                    [imgtype] => indeximg                    [created_at] => 2016-10-26 14:58:14                )            [1] => Array                (                    [id] => 1                    [imgtitle] => sadas                    [imgintro] => asdasd                    [filename] => 147asda.jpg                    [imgtype] => indeximg                    [created_at] => 2016-10-24 14:13:12                )        )    [minimg] => Array        (        ))

Now you only want to traverse the array bigimg

Reply content:
Array(    [bigimg] => Array        (            [0] => Array                (                    [id] => 2                    [imgtitle] => abc                    [imgintro] => asdasd                    [filename] => sda.jpg                    [imgtype] => indeximg                    [created_at] => 2016-10-26 14:58:14                )            [1] => Array                (                    [id] => 1                    [imgtitle] => sadas                    [imgintro] => asdasd                    [filename] => 147asda.jpg                    [imgtype] => indeximg                    [created_at] => 2016-10-24 14:13:12                )        )    [minimg] => Array        (        ))

Now you only want to traverse the array bigimg

Which of the following can meet your requirements?

Var bigimg = [{id: 2}, {imgtitle: 'ABC'}, {imgintro: 'asdasd'}, {filename: 'sda.jpg '}, {filename: 'inputmg '}, {created_at: '2017-10-26 14:58:14'}], [{id: 1}, {imgtitle: 'sadas'}, {imgintro: 'asdasd'}, {filename: '147asda.jpg '}, {filename: 'inputmg'}, {created_at: '2017-10-24 14:13:12 '}] var fn = function (arr) {for (var key in arr) {// if the child element is still an array or an Object, recursive iteration of if (typeof arr [key] = 'object') {fn (arr [key])} else {console. log (key + '=' + arr [key]) }}fn (bigimg)

Solved! In HTML reference$bigimg[0][id]

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.