Access object value using arr[index] as key

Hi, I’m just wondering why is the thirdconsole.log not working as the second one. Since char[1] is returning & why can’t I just pass it in so that I can access the value of & in the entities object?

  **Your code so far**
let entities = {
  "&" : "&",
  "<" : "&lt;",
  ">" : "gt;",
  '"': "&quot;",
  "'": "&apos;"
let char = Object.keys(entities)
console.log(char[1])                         // returns &
console.log(entities["&"])                  // &amp;
console.log(entities["char[1]"])            // undefined

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Edg/94.0.992.38

Challenge: Convert HTML Entities

Link to the challenge:


These are not the same.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.