forward and reverse loop one by one js
JavaScript
var arr = ['red', 'blue', 'black', 'green'];
var currentIndex = 0;
var nextBtn = document.getElementById('nextBtn');
var prevBtn = document.getElementById('prevBtn');
nextBtn.addEventListener('click', nextItem);
prevBtn.addEventListener('click', prevItem);
function nextItem() {
if (currentIndex === (arr.length - 1)) {
return;
}
console.log(
arr[++currentIndex]
);
}
function prevItem() {
if (currentIndex === 0) {
return;
}
console.log(
arr[--currentIndex]
);
}
Also in JavaScript:
- Title
- if clicked outside of div jquery
- Category
- JavaScript
- Title
- iterate object js
- Category
- JavaScript
- Title
- how to craete a shopping cart in node js
- Category
- JavaScript
- Title
- empty array js
- Category
- JavaScript
- Title
- array find method javascript
- Category
- JavaScript
- Title
- functional component react
- Category
- JavaScript
- Title
- dropdown list value react fragment
- Category
- JavaScript
- Title
- events in javascript
- Category
- JavaScript
- Title
- how to take input in javascript in coding
- Category
- JavaScript
- Title
- javascript .firstordefault
- Category
- JavaScript
- Title
- get date now javascript
- Category
- JavaScript
- Title
- enter event in jquery
- Category
- JavaScript
- Title
- angular moment pipe timeAgo
- Category
- JavaScript
- Title
- extend react.component
- Category
- JavaScript
- Title
- conditional rendering with radio buttons
- Category
- JavaScript
- Title
- https package node post request
- Category
- JavaScript
- Title
- ion-fab-button ionic angular
- Category
- JavaScript
- Title
- javascript array concat spread operator
- Category
- JavaScript
- Title
- count occurrences of character in string javascript
- Category
- JavaScript
- Title
- background-image url not working
- Category
- JavaScript
- Title
- how to import jquery in js file
- Category
- JavaScript
- Title
- get value javascript
- Category
- JavaScript
- Title
- dont starve together
- Category
- JavaScript
- Title
- fetch response json or text
- Category
- JavaScript
- Title
- how to add property to object in javascript
- Category
- JavaScript
- Title
- for Loop continue
- Category
- JavaScript
- Title
- javascript button onclick
- Category
- JavaScript
- Title
- insert into specific array index
- Category
- JavaScript
- Title
- Better Array check with Array.isArray Because arrays are not true array in JavaScript, there is no simple typeof check. No problem! Use the method Array.isArray to check…
- Category
- JavaScript
- Title
- javascript 1 + "1"
- Category
- JavaScript
- Title
- how to find id in array javascript
- Category
- JavaScript
- Title
- callback in response node.js
- Category
- JavaScript
- Title
- combine p5 with react
- Category
- JavaScript
- Title
- find the last occurrence of a character in a string javascript
- Category
- JavaScript
- Title
- how to concatenate strings javascript
- Category
- JavaScript
- Title
- expo open app settings
- Category
- JavaScript
- Title
- angular two way property binding
- Category
- JavaScript
- Title
- discord.js dm user
- Category
- JavaScript
- Title
- Check ratelimit discord js
- Category
- JavaScript
- Title
- fizz buzz javascript
- Category
- JavaScript
- Title
- Alert.alert closing expo
- Category
- JavaScript
- Title
- create react app deployment heroku
- Category
- JavaScript
- Title
- how to update angular version
- Category
- JavaScript
- Title
- angular @Output()
- Category
- JavaScript
- Title
- count number of times an element is occuring in an array in javascript
- Category
- JavaScript
- Title
- angular 6 reload current page
- Category
- JavaScript
- Title
- angular sumar labels
- Category
- JavaScript
- Title
- compare dates in javascript
- Category
- JavaScript
- Title
- eslint ignore javascript
- Category
- JavaScript
- Title
- how to write a program that alerts the first 3 letters of the current day in javascript
- Category
- JavaScript
- Title
- alert user javascript
- Category
- JavaScript
- Title
- fsharp newtonsoft json deserialize
- Category
- JavaScript
- Title
- how to remove link in image in jquery
- Category
- JavaScript
- Title
- how to output to console java
- Category
- JavaScript
- Title
- add to json object javascript
- Category
- JavaScript
- Title
- how to version a react app azure pipelines
- Category
- JavaScript
- Title
- disable mouse right click javascript
- Category
- JavaScript
- Title
- coment executer des touche de clavier avec du js
- Category
- JavaScript
- Title
- create bottom navigation bar react native
- Category
- JavaScript
- Title
- for loop javascript
- Category
- JavaScript
- Title
- how to write img jsx
- Category
- JavaScript
- Title
- how to make a random number guessing game in javascript
- Category
- JavaScript
- Title
- express server replit
- Category
- JavaScript
- Title
- how to check if variable is array in js
- Category
- JavaScript
- Title
- javascript array elements search
- Category
- JavaScript
- Title
- convert json to arraylist java
- Category
- JavaScript
- Title
- child process spawn python node js
- Category
- JavaScript
- Title
- flatten an array in javascript
- Category
- JavaScript
- Title
- javacript getHTTPURL
- Category
- JavaScript
- Title
- adding bootstrap to angular
- Category
- JavaScript
- Title
- how to display image in html from json object
- Category
- JavaScript
- Title
- how to set random dice image with js
- Category
- JavaScript
- Title
- add multiple images inside the DOM js
- Category
- JavaScript
- Title
- javascript check if a value is an int
- Category
- JavaScript
- Title
- javascript async fetch file html
- Category
- JavaScript
- Title
- detect a click outside an element javascript
- Category
- JavaScript
- Title
- Cannot deserialize the current JSON array (e.g. [1,2,3]) into type
- Category
- JavaScript
- Title
- convert array string to number
- Category
- JavaScript
- Title
- find and delete element from array js
- Category
- JavaScript
- Title
- font awesome react
- Category
- JavaScript
- Title
- fs writefile node
- Category
- JavaScript
- Title
- how to downgrade node version
- Category
- JavaScript
- Title
- how to delete a variable in js
- Category
- JavaScript
- Title
- how to get textedit on mac without download
- Category
- JavaScript
- Title
- how to wait for an exec command to fininsh in nodejs
- Category
- JavaScript
- Title
- devexpress custom text column field
- Category
- JavaScript
- Title
- create react component class
- Category
- JavaScript
- Title
- array data structure javascipt interview questions
- Category
- JavaScript
- Title
- devextreme custom field
- Category
- JavaScript
- Title
- Hoisting in JavaScript MDN
- Category
- JavaScript
- Title
- convert array object to string javascript
- Category
- JavaScript
- Title
- fix a navbar to top of page js
- Category
- JavaScript
- Title
- how to inject service in component angular 6
- Category
- JavaScript
- Title
- flatten nested array javascript
- Category
- JavaScript
- Title
- how to convert time to am pm in javascript
- Category
- JavaScript
- Title
- and operator in javascript
- Category
- JavaScript
- Title
- find least common multiple javascript
- Category
- JavaScript
- Title
- angular stacked bar
- Category
- JavaScript
- Title
- javascript after split then trim whitespace
- Category
- JavaScript
- Title
- How to get row index and cellindex together in javascript
- Category
- JavaScript