-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.js
31 lines (24 loc) · 1.06 KB
/
history.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// const history=sessionStorage.getItem('historyresult');
// console.log(history);
// for (let i = 0; i < history.length; i++) {
// //console.log(history[i]);
// console.log(i);
// }
// Retrieving and printing each element on a new line
// const retrievedArray = JSON.parse(sessionStorage.getItem("historyresult"));
// retrievedArray.forEach((str) => {
// console.log(str);
// });
// //document.getElementById('history result').innerHTML=history[0];
// const historyResultElement = document.getElementById('history result');
// historyResultElement.innerHTML = retrievedArray.join('<br>');
const retrievedArray = JSON.parse(sessionStorage.getItem("historyresult"));
// Create a copy of the array in reverse order
const reversedArray = [...retrievedArray].reverse();
// Print the elements using forEach
reversedArray.forEach((str) => {
console.log(str);
});
// Or, set the reversed array as the innerHTML of the 'history result' element
const historyResultElement = document.getElementById('history result');
historyResultElement.innerHTML = reversedArray.join('<br>');