I need an array in 'indArray [];' enter the values ​​of the variable 'valCookie' - i.e. indexes on a click, so that the array would keep the cookies and the state of the menu was saved when clicking on the links. How to me to implement competent data drift in an array?

$(document).ready(function () { //index array var indArray = []; var indToCookie; var valCookie; // take index click element $('ul > li > span').click(function() { indToCookie = $('ul > li > span').index(this); $.cookie('nav-item', indToCookie); valCookie = $.cookie('nav-item'); }); $('ul.list-1 > li > span').click(function() { $("ul.list-1 ul").toggleClass('active'); }); }); 
  • indArray.push (here "competent variable data") - Dzianis Sadouski
  • those. indArray.push (valCookie) ;? - Oleg Glushchenko
  • if a final variable is stored in valCookie that needs to be memorized, then that's right - Dzianis Sadouski

1 answer 1

I think you need it.

 $(document).ready(function () { //index array let indArray = []; let indToCookie; let valCookie; // take index click element $("ul > li > span").on("click", ()=> { indToCookie = $("ul > li > span").index(this); $.cookie("nav-item", indToCookie); indArray.push(indToCookie ); }); $("ul.list-1 > li > span").on("click", ()=> { $("ul.list-1 ul").toggleClass("active"); }); }); 

  • I apologize, but what do these code symbols mean "() =>" ?? - Oleg Glushchenko