123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /* let a = {
- name: 'Nikki',
- surname: 'Tikki',
- sex: 'male'
- }
- let b = {
- name: 'Nik',
- surname: 'Tikki',
- fathername: 'Anonovich'
- }
- let c = {
- name: 'Petro',
- surname: 'Tikki',
- age: 10
- } */
- /* debugger; */
- //first attemps to find key)))
- /* let arrayofKeys = ['sex','fathername', 'age'];
- for(let key in a){
- for(let i=0; i<arrayofKeys.length; i++){
- if(key == arrayofKeys[i]){
- alert(key)
- }
- }
- } */
- //how to find key in object, maybe variant with entries better than that
- /* function findFieldsinObject (obj,fieldForSearch){
- for(let key in obj){
- if(key == fieldForSearch){
- alert(`Object contains this field ${key}`);
- }
- }
- }
- */
- /* findFieldsinObject(a,'sex'); */
- /* let persons = [a,b,c]; */
- /* console.log(persons); */
- //show all persons like obj
- /* for(let i=0; i<persons.length; i++){
- console.log(persons[i]);
- }
- //show name and surname of persons
- for(let i=0; i<persons.length; i++){
- console.log(persons[i].name + ' ' + persons[i].surname);
- } */
- /* debugger */;
- //show all keys and values of all objects
- /* for (let i = 0; i<persons.length; i++){
- for(let [key,value]of Object.entries(persons[i])){
-
- console.log(`${key} ${value}`)
- }
- } */
- //attemps to push all keys from all object to one arr
- /* for (let i = 0; i<persons.length; i++){
- let keysarr = [];
- for(let [key,value]of Object.entries(persons[i])){
-
- console.log(`${key} ${value}`)
- keysarr.push(key);
- }
- console.log(keysarr);
- }
- */
- /* let arrOfKeys = [];
- arrOfKeys.push(key);
- console.log(arrOfKeys); */
-
- //add fathername
- /* function addFieldInObject(obj){
- obj["fathername"] = prompt("input fathername", "");
- if(obj["fathername"] == null){
- obj["fathername"] = "";
- }
- alert("fathername add");
- }
- addFieldInObject(a);
- addFieldInObject(b);
- addFieldInObject(c);
- //transform to json
- let jsonPersons = JSON.stringify(persons);
- console.log(jsonPersons); */
- /* var str = "<table border='1'>"
- for (let i=0;i<persons.length;i++){
- str += `<tr><td>${i}</td><td>${persons[i].name}</td> <td>${persons[i].surname}</td><td>${persons[i].fathername}</td><td>${persons[i].age}</td><td>${persons[i].sex}</td></tr>`
- }
- str += "</table>"
- document.write(str) */
- //destructuring
- /* let arr = [1,2,3,4,5, "a", "b", "c"];
- let [odd1,even1,odd2,even2,odd3,...charters] = arr;
- let arr1 = [1,"abc"];
- let [number,[s1='',s2='',s3='']] = arr1;
- let obj = {name: 'Ivan',
- surname: 'Petrov',
- children: [{name: 'Maria'}, {name: 'Nikolay'}]}
- let {name,surname,children:[name1,name2]} = obj;
- let arr2 = [1,2,3,4,5,6,7,10];
- const {length} = arr2;
- const [a,b,...numarr] = arr2;
- */
|