草庐IT

normal_array

全部标签

javascript - Array.fill 重复相同的对象。为什么?

这个问题在这里已经有了答案:Array.prototype.fill()withobjectpassesreferenceandnotnewinstance(7个答案)关闭3年前。vararr=newArray(4).fill({});arr[2].status=true;console.log(arr[0].status);为什么数组填充在所有索引中填充相同的对象?

JavaScript 错误 : "ReferenceError: array is not defined"

我想制作一个JavaScriptarray并通过post请求将其传递到php中的另一个页面我在firebug中遇到错误:ReferenceError:arrayisnotdefined代码如下:$(document).ready(function(){vardata=newarray();//thislinethrowstheerror//HandleSubmitingformdata$("#btnSumbit").click(function(){$('#tblCriteriainput[type=text]').each(function(){data[this.id]=this.

javascript - JS : Filter object array for partial matches

是否可以过滤那些与搜索字符串匹配的对象?constarr=[{title:'Justanexample'},{title:'Anotherexam'},{title:'Somethingdifferent'}]我试过了arr.filter(x=>{returnx.title===searchStr});但这只会过滤完全匹配项,但我需要找到所有部分匹配项。letsearchStr='exam'应该给我两个对象(第一个和第二个),letsearchStr='examp'应该只给我一个对象作为结果。 最佳答案 根据您的问题,我假设您还想匹

javascript - 无法构造 'Blob' : The 1st argument provided is either null, 或无效的 Array 对象。

我今天开始使用filesaver.js。我创建了以下函数:functionsaving(){varblob=newBlob(final_transformation,{type:"text/plain;charset=utf-8"});saveAs(blob,"helloworld.txt");}但是当我调用该函数时,我得到“无法构造‘Blob’:提供的第一个参数要么为空,要么为无效的Array对象。”有什么想法吗? 最佳答案 由于您不会告诉我们final_transformation是什么,我们必须在没有上下文的情况下进行猜测。试

Javascript:替代 Array.prototype.find()?

当我在AngularJS中使用Chrome浏览器时,我遇到了.find()无法正常工作的问题。这是我最初的问题:AngularJS:Array.prototype.find()doesnotworkinChrome这条线失败了:console.log($scope.products_colors);//prints`[Object]0:Objectlength:1__proto__:Array[0]concat:functionconcat(){[nativecode]}constructor:functionArray(){[nativecode]}every:functioneve

javascript - JavaScript 中 "new Array(..)"和 "[..]"的区别?

这个问题在这里已经有了答案:What’sthedifferencebetween"Array()"and"[]"whiledeclaringaJavaScriptarray?(19个回答)关闭8年前。是varmyCars=newArray("Saab","Volvo","BMW");和varmyCars=["Saab","Volvo","BMW"];完全一样吗?

javascript - 在 Chrome 中查找 "normal"行高的像素值

这个问题在这里已经有了答案:JavaScript:FindDIV'sline-height,notCSSpropertybutactualline-height(8个答案)关闭3个月前。我有一个行高设置为“正常”的文本区域。但是,我仍然可以在FireFox中获取实际像素值://firefox>>>$("#post_body").css('line-height')"19.1167px"而我不能在Chrome中://chrome>>>$("#post_body").css('line-height')"normal"如何在Chrome中获取实际的像素行高?

javascript - Array.apply(null, Array(x) ) 和 Array(x) 之间的区别

到底有什么区别:Array(3)//andArray.apply(null,Array(3))第一个返回[undefinedx3]而第二个返回[undefined,undefined,undefined]。第二个可以通过Array.prototype.functions链接,例如.map,但第一个不是。为什么? 最佳答案 有一个区别,一个非常重要的区别。Array构造函数either接受一个数字,给出数组的长度,并创建一个具有“空”索引的数组,或者更准确地说,长度已设置,但数组实际上并不包含任何内容Array(3);//create

javascript - 位置 :sticky : Adding style when the element detaches from normal flow

举个简单的例子:MYNAVBAR和基本样式:#mynav{position:sticky;}我想将以下样式信息应用到我的导航栏仅当它脱离正常流程时,以便从视觉上将其与主要内容分开(在这种情况下带有阴影)box-shadow:0px10px15px0pxrgba(0,0,0,0.75);我可以使用某种伪类或类似媒体查询的东西吗?例如:#mynav:some-pseudo-class{box-shadow:0px10px15px0pxrgba(0,0,0,0.75);}我知道有一些很好的插件,但如果不绕过(相当新的)native功能position:sticky,它们似乎都无法实现它。相反

javascript - react + Apollo : GraphQL errors array not passed into component

根据这些Apollodocs,设置all的error-policy应该使GraphQL响应的errors数组可用于我的Apollo包装的React组件“所以[my]UI可以使用它们。”我的应用程序是通用的,所以我使用此策略很重要,这样错误就不会阻止应用程序完全呈现。问题是,即使我的浏览器开发工具在服务器响应中显示了errors数组,我也无法在我的React组件的props中访问它。同样,props.data.error始终未定义。这是为什么?//ComponentimportReactfrom'react';import{graphql}from'react-apollo';impor