Search code examples
javascriptarraysobject

javascript array, object, key:value


Select all the values of objects in the array. For example,

tutorials = [{title:a, movie:a}, {title:b, movie:b}, {title:c, movie:c}] => a b c.

I want to find the values of the titles of all objects.

Tutorials[number].title was attempted, but it was impossible to obtain the value of the title of all objects.


Solution

  • Zohrab's answer is correct. I am just showing an alternative way:

    let tutorials = [
        {
            title:'a', movie:'a'
        },
        {
            title:'b', movie:'b'
        }, 
        {
            title:'c', movie:'c'
        }
    ]
    
    const titles = [];
    for (tutorial of tutorials) {
      titles.push(tutorial.title)
    }