0

In this example: Say I know the 'title' of a question - is it possible from that, to find what the property 'name' is?

I'm wondering if there is a way to do this, without referencing the property in this example, within each object in 'questions'.

Angular solution welcome.

 var list = {[
     {
        name: blue,
        questions: [
          {
            title: 'what?',
            question:'what is blue?
          },
          {
            title:'why?',
            question: 'why is blue blue?'
          }
        ]
      }....
 ]};
ggilberth
  • 1,128
  • 10
  • 19
  • You seem to be talking about JavaScript objects, not JSON. If you want to use a value in multiple places, put it in a variable: `var name = 'blue'; var item = { name: name, questions: [{ title: 'what?', question: 'what is ' + name + '?' }] }`. – hon2a Nov 26 '14 at 11:05
  • I understand how to use a variable in multiple places - this is not what I wanted. I want a way of being able to find out the value of 'name' - when having only the knowledge of say - 'title' – ggilberth Nov 26 '14 at 11:09
  • Finding items in collections by their property names can be done for example using `_.find()` in the [Lo-Dash utility library](https://lodash.com/docs#find). – hon2a Nov 26 '14 at 11:11
  • @ggilberth I _think_ you're saying you have a property (title) of an object (questions[0]0 And you want to get a property (name) of its parent (list[0]). Maybe this link could help http://stackoverflow.com/questions/2980763/javascript-objects-get-parent – asantaballa Nov 26 '14 at 16:00

1 Answers1

0

It depends of the context, but maybe, if you're looking for a solution with angular, you could use angular's filters.

blandine
  • 93
  • 1
  • 10