function getValue(target, valuePath, defaultValue) {
  var arrStr = valuePath.split(".");
  var finValue = null;
  if(Object.prototype.toString.call(target) === "[object Object]") {for (i of arrStr){
      if(/[A-Za-z]\[0\]/.test(i)){
        var arrA = i.substr(0.1)
        finValue = target[arrA][0]}else if(/[/d]/.test(i)){
        finValue = finValue[0];
      }else{ finValue = finValue[i]; }}}if(Object.prototype.toString.call(target) === "[object Array]") {for (n of arrStr){
      if(/[A-Za-z]\[0\]/.test(n)){
        var arrA = n.substr(0.1)
        finValue = finValue[arrA][0]}else if(/ [0] /.test(n) && finValue ! =undefined){
        finValue = finValue[0];
      }
      else if(/ [0] /.test(n) && finValue == undefined){
        finValue = target[0];
    }else{ finValue = finValue[n]; }}}if( finValue == undefined) {return defaultValue
  }else{
    return finValue
  }
}
var object = { a: [{ b: { c: 3}}};// path: 'a[0].b.c'
var array = [{ a: { b: [1]}}];// path: '[0].a.b[0]'
console.log(getValue(object, "a[0].b.c".0)); 3 / / output
console.log(getValue(array, "[0].a.b[0]".12)); / / output 1
console.log(getValue(array, "[0].a.b[0].c".12)); / / output 12
Copy the code

Above is the code body.

Here is the code for the idea.

// for (const [key, value] of Object.entries(object)) {
// if(Object.prototype.toString.call(value) === "[object Object]"){
// console.log(1);
// }else{
// console.log(2);
/ /}
// }
// console.log("a[0].b.c".split("."));
var arrStr = "a[0].b.c".split(".")
var patt1 = new RegExp("[0].");
// var patt2 = new RegExp(/w)
// for (i of arrStr) {
// if(/[A-Za-z]\[0\]/.test(i)){
/ / the console. The log (i. ubstr (0, 1), i. ubstr (1, 3)); //a [0]; //a [0]
/ /}
// }
// console.log(object['a'][0]['b']['c']);
Copy the code

(If anyone sees this, try to simplify it.)

White, light spray.