node.js - How can i get data from array in express -
i using rest api express ejs in nodejs. api json data below. in data there array inside array. issue want value of feature_image value of guid. when try value show me has no method 'foreach
error.
[ { "id": 161, "title": "compant name 3", "status": "publish", "type": "testimonial", "author": { "id": 1, "username": "admin", "name": "admin", "first_name": "", "last_name": "", "nickname": "admin", "slug": "admin", "url": "", "avatar": "http://2.gravatar.com/avatar/56282b1eb6c5d293a03d2c167924b197?s=96", "description": "", "registered": "2015-04-28t10:14:02+00:00", "meta": { "links": { "self": "http://tryitoneyewear.com/wp-json/users/1", "archives": "http://tryitoneyewear.com/wp-json/users/1/posts" } } }, "content": "<p>sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem </p>\n", "parent": null, "link": "http://tryitoneyewear.com/testimonial/compant-name-3/", "date": "2015-06-04t07:33:29", "modified": "2015-06-04t08:01:26", "format": "standard", "slug": "compant-name-3", "guid": "http://tryitoneyewear.com/?post_type=testimonial&p=161", "excerpt": "<p>sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem</p>\n", "menu_order": 0, "comment_status": "open", "ping_status": "open", "sticky": false, "date_tz": "utc", "date_gmt": "2015-06-04t07:33:29", "modified_tz": "utc", "modified_gmt": "2015-06-04t08:01:26", "meta": { "links": { "self": "http://tryitoneyewear.com/wp-json/posts/161", "author": "http://tryitoneyewear.com/wp-json/users/1", "collection": "http://tryitoneyewear.com/wp-json/posts", "replies": "http://tryitoneyewear.com/wp-json/posts/161/comments", "version-history": "http://tryitoneyewear.com/wp-json/posts/161/revisions" } }, "featured_image": { "id": 28, "title": "dummy_img", "status": "inherit", "type": "attachment", "author": { "id": 1, "username": "admin", "name": "admin", "first_name": "", "last_name": "", "nickname": "admin", "slug": "admin", "url": "", "avatar": "http://2.gravatar.com/avatar/56282b1eb6c5d293a03d2c167924b197?s=96", "description": "", "registered": "2015-04-28t10:14:02+00:00", "meta": { "links": { "self": "http://tryitoneyewear.com/wp-json/users/1", "archives": "http://tryitoneyewear.com/wp-json/users/1/posts" } } }, "content": "<p class=\"attachment\"><a href='http://tryitoneyewear.com/wp-content/uploads/2015/04/dummy_img.jpg'><img width=\"200\" height=\"200\" src=\"http://tryitoneyewear.com/wp-content/uploads/2015/04/dummy_img.jpg\" class=\"attachment-medium\" alt=\"dummy_img\" /></a></p>\n", "parent": null, "link": "http://tryitoneyewear.com/?attachment_id=28", "date": "2015-04-29t06:50:48", "modified": "2015-04-29t06:50:48", "format": "standard", "slug": "dummy_img", "guid": "http://tryitoneyewear.com//wp-content/uploads/2015/04/dummy_img.jpg", "excerpt": null, "menu_order": 0, "comment_status": "open", "ping_status": "open", "sticky": false, "date_tz": "utc", "date_gmt": "2015-04-29t06:50:48", "modified_tz": "utc", "modified_gmt": "2015-04-29t06:50:48", "meta": { "links": { "self": "http://tryitoneyewear.com/wp-json/media/28", "author": "http://tryitoneyewear.com/wp-json/users/1", "collection": "http://tryitoneyewear.com/wp-json/media", "replies": "http://tryitoneyewear.com/wp-json/media/28/comments", "version-history": "http://tryitoneyewear.com/wp-json/media/28/revisions" } }, "terms": [], "source": "http://tryitoneyewear.com/wp-content/uploads/2015/04/dummy_img.jpg", "is_image": true, "attachment_meta": { "width": 200, "height": 200, "file": "2015/04/dummy_img.jpg", "sizes": { "thumbnail": { "file": "dummy_img-150x150.jpg", "width": 150, "height": 150, "mime-type": "image/jpeg", "url": "http://tryitoneyewear.com/wp-content/uploads/2015/04/dummy_img-150x150.jpg" }, "owl_widget": { "file": "dummy_img-180x100.jpg", "width": 180, "height": 100, "mime-type": "image/jpeg", "url": "http://tryitoneyewear.com/wp-content/uploads/2015/04/dummy_img-180x100.jpg" } }, "image_meta": { "aperture": 0, "credit": "", "camera": "", "caption": "", "created_timestamp": 0, "copyright": "", "focal_length": 0, "iso": 0, "shutter_speed": 0, "title": "", "orientation": 0 } } }, "terms": [] } ]
you should learn bit more json , javascript
your json array single object in it. featured_image object value need
your_json[0].featured_image.guid
Comments
Post a Comment