title: How to make an accordion with array in Javascript?
body: <p>I'm trying to make an accordion with HTML, CSS, and Javascript.
  I made it but it displays text from an array in only one accordion item, and not on the other accordion divs and other buttons, who are not working for each accordion. I want to display object text from each array and to make all buttons work, is this possible?
  Thanks anyway.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const datas = [ {
      title: "Can you accept all credit cards",
      content:"Lorem ipsum dolor sit amet consectetur adipisicing elit. Omnis, ipsa? Nam nobis repudiandae ullam,",
  },
  {
      title: "Can you accept all credit cards",
      content:"Lorem ipsum dolor sit amet consectetur adipisicing elit. Omnis, ipsa? Nam nobis repudiandae ullam,",
  },
  {
      title: "Can you accept all credit cards",
      content:"Lorem ipsum dolor sit amet consectetur adipisicing elit. Omnis, ipsa? Nam nobis repudiandae ullam,",
  }
  ];
  
  
  
  let container = document.querySelector(".container");
  let accordion = document.querySelector(".accordion");
  let accordion__content = document.querySelector(".accordion__content");
  
  
  let  accordion__show = document.querySelector(".accordion__show");
  
  
  datas.map((data)=&gt; {
  accordion__show.addEventListener("click" , (e)=&gt; {
      e.preventDefault();
  accordion__content.classList.toggle("show_text");
  accordion__content.innerHTML =  datas[0].content;
  
    if ( accordion__show.innerHTML === "+") {
       accordion__show.innerHTML = "-";
    } else {
  accordion__show.innerHTML = "+"; 
   }
  
  })
  })</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>@import url('https://fonts.googleapis.com/css2?family=Quicksand&amp;display=swap');
  
  body  {
      padding: 0;
      margin: 0;
      background-color: #F2F7FE;
      font-weight: bold;
      font-family: 'Quicksand',sans-serif;
  }
  
  main {
          width: 100%;
      min-height: 500px;
          display: flex;
      align-items: center;
      flex-wrap: wrap;
      flex-direction: column;
      justify-content: center;
  }
  .container {
      width: 100%;
      min-height: 500px;
          display: flex;
      align-items: center;
      flex-direction: column;
      justify-content: center;
  }
  
  .accordion__content {
      display: none;
  }
  
  .show_text {
      display: flex;
      align-items: center;
      justify-content: center;
       padding: 20px;
  }
  
  
  
  
  .accordion {
      width:calc(650px - 30px);
      background-color: white;
      box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  flex-wrap: wrap;
  }
  
  .accordion__header {
      width: 100%;
      min-height: auto;
      display: flex;
      text-align: center;
      align-items: center;
      justify-content: space-around;
      flex-direction: row;
  }
  
  .accordion button {
      border:2px solid gray;
      background-color: transparent;
      padding: 10px 15px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta name="viewport" content="width=device-width"&gt;
      &lt;title&gt;repl.it&lt;/title&gt;
      &lt;link href="style.css" rel="stylesheet" type="text/css" /&gt;
    &lt;/head&gt;
    &lt;body&gt;
  
          &lt;div class="main"&gt;
          &lt;div class="container"&gt;
              &lt;div class="accordion"&gt;
  &lt;div class="accordion__header"&gt;
      &lt;h1&gt;Do you accept all credit cards?&lt;/h1&gt;
      &lt;button class="accordion__show"&gt;+&lt;/button&gt;
  &lt;/div&gt;
              &lt;p class="accordion__content"&gt;&lt;/p&gt;
                  &lt;/div&gt;
                      &lt;div class="accordion"&gt;
  &lt;div class="accordion__header"&gt;
      &lt;h1&gt;Do you accept all credit cards?&lt;/h1&gt;
      &lt;button class="accordion__show"&gt;+&lt;/button&gt;
  &lt;/div&gt;
              &lt;p class="accordion__content"&gt;&lt;/p&gt;
                  &lt;/div&gt;
                      &lt;div class="accordion"&gt;
  &lt;div class="accordion__header"&gt;
      &lt;h1&gt;Do you accept all nonsense cards?&lt;/h1&gt;
      &lt;button class="accordion__show"&gt;+&lt;/button&gt;
  &lt;/div&gt;
              &lt;p class="accordion__content"&gt;&lt;/p&gt;
                  &lt;/div&gt;
          &lt;/div&gt;
          &lt;/div&gt;
      &lt;script src="script.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>