3 changed files with 105 additions and 0 deletions
@ -0,0 +1,33 @@ |
|||||
|
var mojePole = ["Intel", "AMD", "Asus", "NVidia","Samsung", "Nokia","Xiaomi", "ZTE"] |
||||
|
mojePole.sort(); |
||||
|
console.log(mojePole) |
||||
|
|
||||
|
//vypsání všech elementů
|
||||
|
//document.getElementById("demo").innerHTML = mojePole + "<br>";
|
||||
|
//vypsání jednoho elementu
|
||||
|
//document.getElementById("demo").innerHTML += mojePole[0];
|
||||
|
|
||||
|
|
||||
|
document.getElementById("demo").innerHTML = "Mám "+ mojePole.length + " Oblíbneých IT firem <br>"; |
||||
|
|
||||
|
// for metoda vypisování jednotlivých věcí z Pole
|
||||
|
// for (let i = 0; i < mojePole.length; i++) {
|
||||
|
// const element = mojePole[i];
|
||||
|
// var arrayText = "Mezi moje oblíbené IT firmy patří:"+ element+"<br>";
|
||||
|
// document.getElementById("demo").innerHTML += arrayText;
|
||||
|
// }
|
||||
|
|
||||
|
document.getElementById("demo").innerHTML += mojePole.join(" & "); |
||||
|
|
||||
|
mojePole.pop() |
||||
|
console.log(mojePole); |
||||
|
|
||||
|
mojePole.push("GIGABYTE"); |
||||
|
console.log(mojePole); |
||||
|
|
||||
|
mojePole.shift(); |
||||
|
console.log(mojePole); |
||||
|
|
||||
|
mojePole[3] = "ERROR"; |
||||
|
console.log(mojePole); |
||||
|
|
@ -0,0 +1,25 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html lang="en"> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"> |
||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
|
<title>Document</title> |
||||
|
</head> |
||||
|
<body> |
||||
|
<h1>JS Array</h1> |
||||
|
|
||||
|
|
||||
|
<p id="demo"></p> |
||||
|
<hr> |
||||
|
<textarea name="todoitem" id="todoitem" cols="30" rows="10"></textarea> |
||||
|
<br> |
||||
|
<button id="todobtn" onclick="addItem()">Přidat Úkol |
||||
|
</button> |
||||
|
|
||||
|
<ul id="todolist"></ul> |
||||
|
|
||||
|
<script src="app.js"></script> |
||||
|
<script src="todo.js"></script> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,47 @@ |
|||||
|
let todoarray = []; |
||||
|
|
||||
|
//načtení hodnot z paměti
|
||||
|
let localTodo = localStorage.getItem("todoLocal"); |
||||
|
let flocalTodo = JSON.parse(localTodo); |
||||
|
//vygenerovaní uloženého textu z paměti
|
||||
|
for (let i = 0; i < flocalTodo.length; i++) { |
||||
|
const element = flocalTodo[i]; |
||||
|
todoarray.push(element); |
||||
|
} |
||||
|
todoarray.forEach(createList); |
||||
|
//kontrola
|
||||
|
console.log(todoarray); |
||||
|
//přidání textu
|
||||
|
function addItem() { |
||||
|
let text = document.getElementById("todoitem").value; |
||||
|
|
||||
|
//přidání do pole
|
||||
|
todoarray.push(text); |
||||
|
|
||||
|
//uložení do paměti počítače
|
||||
|
let jsonPole = JSON.stringify(todoarray); |
||||
|
localStorage.setItem("todoLocal",jsonPole); |
||||
|
|
||||
|
console.log(todoarray); |
||||
|
|
||||
|
//vygenerovani list
|
||||
|
//document.getElementById("todolist").innerHTML += "<li>" + todoarray + "</li>";
|
||||
|
document.getElementById("todolist").innerHTML = ""; |
||||
|
todoarray.forEach(createList); |
||||
|
|
||||
|
} |
||||
|
//*ForEach* funkce pro generovani listu
|
||||
|
function createList(value, index){ |
||||
|
var deleteitem = "<button onclick=\"removeItem("+index+")\">DELETE</button>"; |
||||
|
document.getElementById("todolist").innerHTML += "<li>" + value + deleteitem + "</li>" |
||||
|
} |
||||
|
//odstranění listu
|
||||
|
function removeItem(index) { |
||||
|
//odstranění 1 itemu z pole
|
||||
|
todoarray.splice(index,1) |
||||
|
//znova generovaní listu
|
||||
|
document.getElementById("todolist").innerHTML = ""; |
||||
|
todoarray.forEach(createList); |
||||
|
let jsonPole = JSON.stringify(todoarray); |
||||
|
localStorage.setItem("todoLocal",jsonPole); |
||||
|
} |
Loading…
Reference in new issue