Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
Loop through an array to check for new object

let movies = [];
const addMovie = (ev) => {
  ev.preventDefault();
  let movie = {
    id: Date.now(),
    title: document.getElementById('title').value,
    year: document.getElementById('yr').value
  }
  movies.push(movie);
  document.forms[0].reset();
  console.warn('added', {
    movies
  });
  let pre = document.querySelector('#msg pre');
  pre.textContent = '\n' + JSON.stringify(movies, '\t', 2);
  var SaveInfo = JSON.parse(localStorage.getItem('MyMovieList'));
  document.getElementById("text").innerHTML = SaveInfo;
  console.log(SaveInfo[0].id);
  localStorage.setItem('MyMovieList', JSON.stringify(movies));
}

document.addEventListener('DOMContentLoaded', () => {
    document.getElementById('btn').addEventListener('click', addMovie);
  }

);
<form>
  <div class="formBox">
    <label for="title">Movie</label>
    <input type="text" id="title" placeholder="Title" />
  </div>
  <div class="formBox">
    <label for="yr">Year</label>
    <input type="number" id="yr" placeholder="Year" />
  </div>
  <div class="formBox">
    <button id="btn">Click to Add</button>
  </div>
  <div id="msg">
    <pre></pre>
    <p id="text"></p>
  </div>
</form>

So I have 2 input, which values goes to the local storage as an array. So I want to check if there’s a new object added to the array when I click on submit, then if yes, I want to take the object property/values of that array and put it in an element in html.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!