3 persons
var a = {
name: "Ivan",
surname: "Ivanov",
}
var b = {
name: "Petr",
surname: "Petrov",
}
var c = {
name: "Alex",
surname: "Sidarov",
}
different fields
var a = {
name: "Ivan",
surname: "Ivanov",
}
var b = {
name: "Petr",
surname: "Petrov",
}
var c = {
name: "Alex",
surname: "Sidarov",
}
a.age = 20;
b.fathername = "Nikolai";
c.sex = "male";
fields check
var a = {
name: "Ivan",
surname: "Ivanov",
}
var b = {
name: "Petr",
surname: "Petrov",
}
var c = {
name: "Alex",
surname: "Sidarov",
}
a.age = 20;
b.fathername = "Nikolai";
c.sex = "male";
if("age" in a){
alert(a.age);
}
if("fathername" in b){
alert(b.fathername);
}
if("sex" in c){
alert(c.sex);
}
array of persons
var a = {
name: "Ivan",
surname: "Ivanov",
}
var b = {
name: "Petr",
surname: "Petrov",
}
var c = {
name: "Alex",
surname: "Sidarov",
}
a.age = 20;
b.fathername = "Nikolai";
c.sex = "male";
var persons = [a,b,c,
{
name: "pasha",
surname: "efimenko",
age: 22
}
]
loop of persons
var a = {
name: "Ivan",
surname: "Ivanov",
}
var b = {
name: "Petr",
surname: "Petrov",
}
var c = {
name: "Alex",
surname: "Sidarov",
}
a.age = 20;
b.fathername = "Nikolai";
c.sex = "male";
var persons = [a,b,c,
{
name: "pasha",
surname: "efimenko",
age: 22
}
]
for (var i = 0; i < persons.length; i++) {
console.log(persons[i]);
}
loop of fields loop of persons
var a = {
name: "Ivan",
surname: "Ivanov",
}
var b = {
name: "Petr",
surname: "Petrov",
}
var c = {
name: "Alex",
surname: "Sidarov",
}
a.age = 20;
b.fathername = "Nikolai";
c.sex = "male";
var persons = [a,b,c,
{
name: "pasha",
surname: "efimenko",
age: 22
}
]
for (var i = 0; i < persons.length; i++) {
var j = 0;
for (var key in persons[i]) {
j++;
if(j < 3){
console.log(key + ": " + persons[i][key]);
}
}
console.log("\n");
}
loop of loop of keys
var a = {
name: "Ivan",
surname: "Ivanov",
}
var b = {
name: "Petr",
surname: "Petrov",
}
var c = {
name: "Alex",
surname: "Sidarov",
}
a.age = 20;
b.fathername = "Nikolai";
c.sex = "male";
var persons = [a,b,c,
{
name: "pasha",
surname: "efimenko",
age: 22
}
]
for (var i = 0; i < persons.length; i++) {
var key = Object.keys(persons[i]);
for (var c = 0; c < key.length; c++) {
if(c < 2)
console.log(key[c] + ": " + persons[i][key[c]]);
}
console.log("\n");
}
loop of loop with optional fields
var a = {
name: "Ivan",
surname: "Ivanov",
}
var b = {
name: "Petr",
surname: "Petrov",
}
var c = {
name: "Alex",
surname: "Sidarov",
}
a.age = 20;
b.fathername = "Nikolai";
c.sex = "male";
var persons = [a,b,c,
{
name: "pasha",
surname: "efimenko",
age: 22
}
]
var add = "";
for (var i = 0; i < persons.length; i++) {
var key = Object.keys(persons[i]);
for (var c = 0; c < key.length; c++) {
if(c < 2)
console.log(key[c] + ": " + persons[i][key[c]]);
if(c >= 2)
add += "\n" + key[c] + ": " + persons[i][key[c]];
}
console.log("\n");
}
console.log("Дополнительные поля:" + add);
fullName
var a = {
name: "Ivan",
surname: "Ivanov",
}
var b = {
name: "Petr",
surname: "Petrov",
}
var c = {
name: "Alex",
surname: "Sidarov",
}
a.age = 20;
a.petr = "Ivanovich";
b.fathername = "Nikolai";
b.petr = "Nikolayovich";
c.sex = "male";
c.petr = "Alexandrovich";
var persons = [a,b,c,
{
name: "pasha",
surname: "efimenko",
age: 22,
petr: "Alexandrovich"
}
]
for (var i = 0; i < persons.length; i++) {
persons[i].fullName =persons[i].surname + " " + persons[i].name + " " + persons[i].petr;
}
serialize and deserialize
var a = {
name: "Ivan",
surname: "Ivanov",
}
var b = {
name: "Petr",
surname: "Petrov",
}
var c = {
name: "Alex",
surname: "Sidarov",
}
a.age = 20;
a.petr = "Ivanovich";
b.fathername = "Nikolai";
b.petr = "Nikolayovich";
c.sex = "male";
c.petr = "Alexandrovich";
var persons = [a,b,c,
{
name: "pasha",
surname: "efimenko",
age: 22,
petr: "Alexandrovich"
}
]
var json = JSON.stringify(persons);
var k = JSON.parse(json);
k[4] = k[3];
var j = JSON.stringify(k);
HTML
HTML optional fields
HTML tr color
HTML th optional
jQ HTML th optional
jQ HTML th optional inputs
Задание на синий пояс.
Задание на черный пояс
var histor = ["1","2","1","2"];
var predictArray = {};
var predictValue;
while(true){
predictValue = predictArray[histor[0] + histor[1] + histor[2] + histor[3]];
if(predictValue)
console.log(predictValue);
else{
console.log(Math.ceil(Math.random() * 2) + "rand");
}
var newValue = prompt("Введите 1 или 2");
if(!newValue)
break;
predictArray[histor[0] + histor[1] + histor[2] + histor[3]] = newValue;
histor.push(newValue);
histor.shift();
}