Finding key values in Multidimensional arrays or Nested array in Javascript [duplicate]

三世轮回 提交于 2019-12-13 03:25:52

问题


In an example like this, I'm trying to get inside the array of the 'new folder' to take out the keys from the information array that is nested inside the "new folder' array.

    let info = [
    {
    	fileName: ‘new folder’,
    	size: 233423,
    	information:
	{ 
	       created: ‘2014-06-06’,
	       modified: ‘2016-03-04

	}
    },
    {
    	fileName: ‘untitled’,
    	size: 554,
    	information: 
	{
	      where: ‘desktop’
	  
	}
    },
    {
    	fileName: ‘documents’,
    	size: 743482,
    	information: ‘created yesterday‘
	
    }

For now I tried

console.log(info[0].information)

It does the trick but I was wondering if there was another way to do it?

I also was trying to get the 'modified' key of the 'new folder' array with

console.log(info[0].information.modified)

which again worked, but I don't know if this would seem as hard coding?

来源:https://stackoverflow.com/questions/53144345/finding-key-values-in-multidimensional-arrays-or-nested-array-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!