An object comes, I need to get its properties from it, the ones in allfilms, I just don’t know how to do it: I tried it like this:

var test = projects.data.allfilms 

but the data is obtained: [rosdestvenskaya istoriya: object, sreck: object] . etc.

How to make it so: ["rosdestvenskaya istoriya", "sreck", "sauth parck"] ... etc.

 var projects = [{ "data": { "allfilms": { "rosdestvenskaya istoriya": {}, "sreck": {}, "lednikoviy period": {}, "simsoni": {}, "sauth parck": {}, "rapuncel": {} } } }]; 
  • 3
    Dear, all week you write fairly simple, vaguely worded, poorly designed questions. Please pay a little more attention to the formulation of questions and your own attempts to solve problems. Perhaps, also, you should take the time to systematize the knowledge on the development in this area and read something from the fundamental books on JS. - LbISS
  • one
    My comment pays more attention to systematic carelessness. The example given by you was incorrect and would not even be fulfilled. You asked about allfilms, and in the example you gave the allbrand field. The array declaration is not closed, brackets climbs for limiting the code area, in the text of a typo. - LbISS
  • You are right, you need to spend more time wording the question. I did not understand you correctly, I'm sorry ... I just started learning js, before that, css and html, I studied ... I read learn.javascript about literature. I’m planning further on David Flammus, although they say that it is difficult to begin with ... - Valeriy1996
  • Why do you insult " David Flanagan " like this ... - Dmitriy Simushev

2 answers 2

We need to hasOwnProperty over the keys of the object, while adding a check to hasOwnProperty so as not to include inherited properties by accident.

 var test = []; for(var k in projects.data.allfilms) { if(projects.data.allfilms.hasOwnProperty(k)) { test.push(k); } } 

    If you do not need the support of old browsers, you can use Object.keys :

     Object.keys(projects.data.allfilms); 

    And if you still need, you can use either polyfil or, the method proposed by @LbISS .