Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript func(foo).push(bar)返回一个整数_Javascript - Fatal编程技术网

Javascript func(foo).push(bar)返回一个整数

Javascript func(foo).push(bar)返回一个整数,javascript,Javascript,所以我有一个函数“profile”,它返回一个数组。 我有一个函数“TMYW”,我想把它的结果添加到profile返回的数组中。所以我试过这样的方法: profile(m.hours).push(TMYW(m.hours)); var b = profile(m.hours); b.push(TMYW(m.hours)); 有趣的是,整个语句返回整数3 只是好奇为什么会这样。显然,通过这样做很容易得到预期的结果: profile(m.hours).push(TMYW(m.hours));

所以我有一个函数“profile”,它返回一个数组。 我有一个函数“TMYW”,我想把它的结果添加到profile返回的数组中。所以我试过这样的方法:

profile(m.hours).push(TMYW(m.hours));
var b = profile(m.hours);
b.push(TMYW(m.hours));
有趣的是,整个语句返回整数3

只是好奇为什么会这样。显然,通过这样做很容易得到预期的结果:

profile(m.hours).push(TMYW(m.hours));
var b = profile(m.hours);
b.push(TMYW(m.hours));

关于使用,请参见以下内容:

push()方法将一个或多个元素添加到数组的末尾,并返回数组的新长度

因此,在你的情况下:

var b = profile(m.hours); // returns an array
b.push(TMYW(m.hours)); // returns the new length of b

关于使用,请参见以下内容:

push()方法将一个或多个元素添加到数组的末尾,并返回数组的新长度

因此,在你的情况下:

var b = profile(m.hours); // returns an array
b.push(TMYW(m.hours)); // returns the new length of b

:“返回:调用该方法的对象的新长度属性。”是否询问为什么
push
返回一个数字,或者为什么表达式的值是该表达式求值时执行的最后一个操作的结果?:“返回:调用该方法的对象的新长度属性。”您是否在询问为什么
push
返回一个数字,或者为什么表达式的值是在计算该表达式时执行的最后一个操作的结果?