0

Using the below array of objects I want to convert just the array identifier "Giants" to a string.

But every bit of code that I have attempted is returning a string of the entire array. I have gone back and forth across the internet but have not found anything stating something like this which seems so simple. So it leads me to think I am missing something really obvious here.

let Giants = [{
        name: "Manning",
        power: 99,
        position: "QB",
        random: getRandNum(1, 10)
    },
    {
        name: "Toomer",
        power: 85,
        position: "WR",
        random: getRandNum(1, 10)
    },
];
  • Yes, returned as a string. In the tutorials I have read they have called a variable name an identifier. – Kevin O'Neill Sep 08 '20 at 19:05
  • Got it, I think the linked question is the same and it has a couple of answers. – takendarkk Sep 08 '20 at 19:05
  • 2
    *Why* do you want this? These seems likely an XY problem, e.g., you don't want a variable named `Giants`, you want an object with a `Giants` key, with the players under that. – Dave Newton Sep 08 '20 at 19:06
  • I don't think that's possible? You want to get "Giants" as a string output somehow using only the variable Giants above? – hyperdrive Sep 08 '20 at 19:11
  • I had posted question number 63766749 that is in some way the opposite, where I eventually want an HTML input string to convert to the array name, for the purpose of having that array be used in a loop that returns pts, that can be used for whichever team has the ball. In the case of this question, I want to use whatever array name is in the loop in a string at the end that says + "has 20 pts." – Kevin O'Neill Sep 08 '20 at 19:23
  • I suppose I see what @Dave is saying in that I could add a key called `TeamName: Giants` within the array, and then call for that in the string. `TeamName + "has x pts`. – Kevin O'Neill Sep 08 '20 at 19:34
  • @KevinO'Neill No, I'm saying you have an object with a `Giants` key, and retrieve the team members that way. – Dave Newton Sep 08 '20 at 19:54
  • @DaveNewton. OK, I will go back and review the parts of an object to better understand that. I am a little confused by keys and properties and from what I am reading it seems like two different terms for the same thing. If not I go back to the comprehension drawing board. – Kevin O'Neill Sep 08 '20 at 20:06
  • I found this question on Stack. It helped. [**Properties vs. Keys vs. Values in JavaScript**](https://stackoverflow.com/questions/28648090/properties-vs-keys-vs-values-in-javascript) – Kevin O'Neill Sep 08 '20 at 20:23

0 Answers0