1. function getPersonInfo(one, two, three) {
  2. console.log(one);
  3. console.log(two);
  4. console.log(three);
  5. }
  6.  
  7. const person = "Lydia";
  8. const age = 21;
  9.  
  10. getPersonInfo`${person} is ${age} years old`;
  11. A: Lydia 21 ["", "is", "years old"]
  12. B: ["", "is", "years old"] Lydia 21
  13. C: Lydia ["", "is", "years old"] 21
  14. 答案 B
  15. 如果使用标记的模板字符串,则第一个参数的值始终是字符串值的数组。 其余参数获取传递到模板字符串中的表达式的值!
  1. let a = 3;
  2. let b = new Number(3);
  3. let c = 3;
  4.  
  5. console.log(a == b);
  6. console.log(a === b);
  7. console.log(b === c);

  8. A: true false true
  9. B: false false true
  10. C: true false false
  11. D: false true true
  12.  
  13. 答案: C
  1. class Chameleon {
  2. static colorChange(newColor) {
  3. this.newColor = newColor;
  4. }
  5.  
  6. constructor({ newColor = "green" } = {}) {
  7. this.newColor = newColor;
  8. }
  9. }
  10.  
  11. const freddie = new Chameleon({ newColor: "purple" });
  12. freddie.colorChange("orange");

  13. A: orange
  14. B: purple
  15. C: green
  16. D: TypeError
  17.  
  18. 答案: D
  1. function Person(firstName, lastName) {
  2. this.firstName = firstName;
  3. this.lastName = lastName;
  4. }
  5.  
  6. const lydia = new Person("Lydia", "Hallie");
  7. const sarah = Person("Sarah", "Smith");
  8.  
  9. console.log(lydia);
  10. console.log(sarah);

  11. A: Person {firstName: "Lydia", lastName: "Hallie"} and undefined
  12. B: Person {firstName: "Lydia", lastName: "Hallie"} and Person {firstName: "Sarah", lastName: "Smith"}
  13. C: Person {firstName: "Lydia", lastName: "Hallie"} and {}
  14. D:Person {firstName: "Lydia", lastName: "Hallie"} and ReferenceError
  15.  
  16. 答案: A
  17. 对于sarah,我们没有使用new关键字。 使用new时,它指的是我们创建的新空对象。 但是,如果你不添加new它指的是全局对象!
  18. 我们指定了this.firstName等于'Sarah和this.lastName等于Smith。 我们实际做的是定义global.firstName ='Sarah'和global.lastName ='Smith sarah本身的返回值是undefined
  1. const obj = { 1: "a", 2: "b", 3: "c" };
  2. const set = new Set([1, 2, 3, 4, 5]);
  3.  
  4. obj.hasOwnProperty("1");
  5. obj.hasOwnProperty(1);
  6. set.has("1");
  7. set.has(1);

  8. A: false true false true
  9. B: false true true true
  10. C: true true false true
  11. D: true true true true
  12.  
  13. 答案: C
  14. 所有对象键(不包括Symbols)都会被存储为字符串,即使你没有给定字符串类型的键。 这就是为什么obj.hasOwnProperty'1')也返回true
  15. 上面的说法不适用于Set 在我们的Set中没有“1”:set.has'1')返回false 它有数字类型1set.has1)返回true
  1. const a = {};
  2. const b = { key: "b" };
  3. const c = { key: "c" };
  4.  
  5. a[b] = 123;
  6. a[c] = 456;
  7.  
  8. console.log(a[b]);

  9. A: 123
  10. B: 456
  11. C: undefined
  12. D: ReferenceError
  13.  
  14. 答案: B
  15. 对象键自动转换为字符串。我们试图将一个对象设置为对象a的键,其值为123
  16. 但是,当对象自动转换为字符串化时,它变成了[Object object]。 所以我们在这里说的是a["Object object"] = 123 然后,我们可以尝试再次做同样的事情。 c对象同样会发生隐式类型转换。那么,a["Object object"] = 456
  1. 0;
  2. new Number(0);
  3. ("");
  4. (" ");
  5. new Boolean(false);
  6. undefined;

  7. A: 0, '', undefined
  8. B: 0, new Number(0), '', new Boolean(false), undefined
  9. C: 0, '', new Boolean(false), undefined
  10. D: 所有都是假值
  11.  
  12. 答案: A
  13. JavaScript中只有6个假值:
  14.  
  15. undefined
  16. null
  17. NaN
  18. 0
  19. '' (empty string)
  20. false
  21.  
  22. 函数构造函数,如new Numbernew Boolean都是真值。
  1. (() => {
  2. let x, y;
  3. try {
  4. throw new Error();
  5. } catch (x) {
  6. (x = 1), (y = 2);
  7. console.log(x);
  8. }
  9. console.log(x);
  10. console.log(y);
  11. })();

  12. A: 1 undefined 2
  13. B: undefined undefined undefined
  14. C: 1 1 2
  15. D: 1 undefined undefined
  16.  
  17. 答案: A
  18. catch块接收参数x。当我们传递参数时,这与变量的x不同。这个变量x是属于catch作用域的。
  19. 之后,我们将这个块级作用域的变量设置为1,并设置变量y的值。 现在,我们打印块级作用域的变量x,它等于1
  20. catch块之外,x仍然是undefined,而y2 当我们想在catch块之外的console.log(x)时,它返回undefined,而y返回2
  1. setInterval(() => console.log("Hi"), 1000);
  2.  
  3. A:一个唯一的id
  4. B:指定的毫秒数
  5. C:传递的函数
  6. Dundefined
  7.  
  8. 答案: A
  9. 它返回一个唯一的id id可用于使用clearInterval()函数清除该定时器。

from:https://juejin.im/post/5d0644976fb9a07ed064b0ca

https://juejin.im/post/5bf769e0518825773a2ebfe5#comment

  1. 实现一个get函数,使得下面的调用可以输出正确的结果
  2. const obj = { selector: { to: { toutiao: "FE Coder"} }, target: [1, 2, { name: 'byted'}]};
  3.  
  4. get(obj, 'selector.to.toutiao', 'target[0]', 'target[2].name');
  5. // [ 'FE Coder', 1, 'byted']
  1. function get(data, ...args) {
  2. const res = JSON.stringify(data);
  3. return args.map((item) => (new Function(`try {return ${res}.${item} } catch(e) {}`))());
  4. }
  5.  
  6. const obj = { selector: { to: { toutiao: "FE Coder"} }, target: [1, 2, { name: 'byted'}]};
  7.  
  8. console.log(get(obj, 'selector.to.toutiao', 'target[0]', 'target[2].name', 'asd'));
  1. 有人提到了那种Function的方式没办法处理以下的处理:
  2. let obj = {time : new Date(), a : "this is a", b : 30};
  3.  
  4. 因为JSON.stringfy后,DateFunctionRegExp类型的变量都会失效。对于这种情况,评论区有个大佬(冯恒智)也提到了一种很好的解决方案:
  5. function get(data, ...args) {
  6. return args.map((item) => (new Function('data',`try {return data.${item} } catch(e) {}`))(data));
  7. }
  1. 1、数组的索引和对象key有什么关系?
  2. 数组是对象的特殊形式,使用方括号访问数组元素和使用方括号访问对象属性一样。JavaScript将指定的数字索引值转换成字符串——索引1变成"1"——然后将其作为属性名来使用。数组的特别之处在于,当使用小于2^32的非负整数作为属性名时数组会自动维护其length属性。
  3. // 索引到属性名的转化
  4. let arr = [1,2,3];
  5. console.log(arr[1]) //
  6. console.log(arr["1"]) //

  7. 所有的数组都是对象,可以为其创建任意名字的属性,不过,只有在小于2^32的非负整数才是索引,数组才会根据需要更新length。事实上数组的索引仅仅是对象属性名的一种特殊类型,这意味着JavaScript数组没有“越界”错误的概念。当查询任何对象中不存在的属性时,不会报错,只会得到undefined
  8. let arr = [];
  9. arr["a"] = 1;
  10. console.log(arr,arr.length) // arr是[a:1] length是0

  11. 对于使用负数或非整数的情况,数值会转换为字符串,字符串作为属性名来用,当时只能当做常规的对象属性,而非数组的索引。
  12. let arr = [];
  13. arr[-1.23] = 0;
  14. console.log(arr,arr.length) // arr是[-1.23: 0] length是0
  15.  
  16. 使用非负整数的字符串或者一个跟整数相等的浮点数时,它就当做数组的索引而非对象属性。
  17. let arr = [];
  18. arr["100"] = 'a';
  19. console.log(arr,arr.length) // arr 是[empty × 100, "a"],length 是101
  20.  
  21. let arr1 = [];
  22. arr1[1.0000] = 'b';
  23. console.log(arr1,arr1.length) // arr 是[empty, "b"],length 是2

from:https://juejin.im/post/5b684ef9e51d451964629ba1

数组的性能提升:http://www.wemlion.com/post/javascript-array-evolution-performance/

js 不常用面试题 数组对象深度取值的更多相关文章

  1. js变量作为数组对象的键值方法

    js变量作为数组对象的键值方法,变量键值获取数组值 js也可以像php的数组一样用下标获取数组的值,方法是: var arr = {'key':'abc'}; var key = 'key'; con ...

  2. js 定义像java一样的map方便取值【转】

    js 定义像java一样的map方便取值.  百度有位大神说"js对象本身就是一种Map结构",这真是一段让人欢天喜地的代码. <script> //定义一个全局map ...

  3. ACCESS常用数字类型的说明和取值范围

    下面是ACCESS常用数字类型的说明和取值范围列表明供参考 数字类型                 范围 Byte(字节)            介于 0 到 255 之间的整型数. Integer ...

  4. js学习---常用的内置对象(API)小结 :

    内置对象(API): 日期 Date: getFullYear() 返回完整的4位的年份  如:2016 getMonth()    返回月份,从0开始 getDate()   返回当前月的第几天,当 ...

  5. js中常用的内置对象

    Arguments 函数参数集合 arguments[ ] 函数参数的数组 Arguments 一个函数的参数和其他属性 Arguments.callee 当前正在运行的函数     Argument ...

  6. Js数组对象的属性值升序排序,并指定数组中的某个对象移动到数组的最前面

    需求整理: 本篇文章主要实现的是将一个数组的中对象的属性值通过升序的方式排序,然后能够让程序可以指定对应的数组对象移动到程序的最前面. 数组如下所示: var arrayData= [{name: & ...

  7. js valueOf()函数用于返回指定对象的原始值

    valueOf()函数用于返回指定对象的原始值. 该方法属于Object对象,由于所有的对象都"继承"了Object的对象实例,因此几乎所有的实例对象都可以使用该方法. 对象 返回 ...

  8. php 数组定义、取值和遍历

    <?php //常用函数 //生成随机数 //echo rand(1,10); //两个参数来确定随机数的范围 //日期时间函数 //var_dump(time()); //取当前时间的UNIX ...

  9. Jquery常用操作:checkbox、select取值,radio、checkbox、select选中及其相关

    常用Jquery操作:checkbox取值.select取值.radio选中.checkbox选中.select选中及其相关: 1.影藏页面元素 使用jquery真的很方便,比如要控制div的显示与隐 ...

随机推荐

  1. 亮瞎你狗眼的写代码体验狂拽酷炫效果 activate-power-mode

    年末了,整理一些收藏的资料,没想到发现一个敲代码的装逼神器; 话不多说上图 我是用idea装的,其他编辑器请自行查找 Preferences -> Plugins -> Install p ...

  2. 【git】本地git bash连接远程库github

    重要参考: https://www.liaoxuefeng.com/wiki/896043488029600 https://segmentfault.com/a/1190000003728094 正 ...

  3. Spark学习(一)——Spark运行架构

    基本概念 在具体讲解Spark运行架构之前,需要先了解几个重要的概念: RDD:是弹性分布式数据集(Resilient Distributed Dataset)的简称,是分布式内存的一个抽象概念,提供 ...

  4. 解决cron不执行的问题

    在FreeBSD5.4下面做开发,需要定期备份mysql数据,开始在网上找了bash的脚本,但是执行无效,一怒之下,使用php来写,嘿嘿,其实php写脚本也不错滴.备份其实就是把mysql的数据库文件 ...

  5. 通过daemon.json配置docker 2375 API端口,配置私有http仓库

    编辑daemon.json vi /etc/docker/daemon.json 配置如下内容即可 { "hosts":[ "tcp://0.0.0.0:2375&quo ...

  6. SHELL中执行Oracle SQL语句查询性能视图

    数据库日志是否报错信息 vi check_log.sh #!/bin/bash # Created : 2019.10.10 # Updated : # Author : # Description ...

  7. IDEA里面maven菜单解读

  8. Python基本语法_控制流语句_if/while/for

    目录 目录 前言 软件环境 If 语句 While循环 break continue for 循环 遍历String 遍历Tuple 遍历List 遍历Dictionary 最后 前言 控制流语句用于 ...

  9. 52N皇后II

    题目:给定一个整数 n,返回 n 皇后不同的解决方案的数量. 来源:https://leetcode-cn.com/problems/n-queens-ii/ 法一: 自己的代码  时间超过百分之90 ...

  10. mysql 8.0.12 安装配置方法图文教程

    一.安装 1.从网上下载MySQL8.0.12版本,下载地址 2. 下载完成后解压 我解压的路径是:D:\Java\mysql-8.0.12-winx64 3. 配置文件 首先在解压的路径下查看是否含 ...