首页 \ 问答 \ item有值,但在Uint8Array中返回'undefined'(item has value but in Uint8Array return 'undefined')

item有值,但在Uint8Array中返回'undefined'(item has value but in Uint8Array return 'undefined')

嗨,我有这样的Uint8Array

var ar = new Uint8Array();
ar[0] = 'G';
ar[1] = 0x123;

第二个索引是一个十六进制数,我想检查ar[1]是否大于零或不是,所以我写这个代码:

if(ar[1] > 0){
  console.log("OK");
}
else{
  console.log("NOP")
}

但如果我写console.log(ar[1])我得到'undefined'。 这是我创建的一个简单的jsbin


hi i have Uint8Array like this

var ar = new Uint8Array();
ar[0] = 'G';
ar[1] = 0x123;

the second index is a hexa decimal number and i want to check ar[1] is grater than zero or not so i write this code :

if(ar[1] > 0){
  console.log("OK");
}
else{
  console.log("NOP")
}

but if i write console.log(ar[1]) i get 'undefined'. this is a simple jsbin that i created.


原文:https://stackoverflow.com/questions/45343505
更新时间:2023-01-09 19:01

最满意答案

如果在扫描阵列期间从未设置过mini ,则minimum函数可能会返回未初始化的值。 我不确定你的逻辑应该是什么,但也许你应该在你的函数顶部初始化mini = 0或做其他事情以防止这种情况发生。 您没有指定给定矩阵中应该包含的内容,但作为示例,所有零的矩阵将触发此行为。


Your function minimum could possibly return an uninitialized value, if mini was never set during your scan of the array. I'm not sure what your logic is supposed to be, but perhaps you should initialize mini = 0 at the top of your function or do something else to prevent this from happening. You didn't specify what was supposed to be in the given matrix, but as an example a matrix of all zeroes would trigger this behavior.

相关问答

更多
  • 当x == 0时,你的sol不会终止。 当x为1时,它很好,因为x2, x3, x4都是0,并且它们的和小于x ,这意味着第二个保护是真的,没有递归。 但是,当输入为0时,递归情况会启动,并且它永远不会终止。 Your sol doesn't terminate when the x == 0. When x is 1 it is fine because all of x2, x3, x4 are 0, and their sum is less than x, meaning the second gu ...
  • 好吧,一个代码,这样的代码: ++*p++应该避免,因为它通常很难阅读。 其次,问题是您正在修改字符串文字 。 这是未定义的行为。 不要这样做。 相反,将您的声明更改为: char p[] = "hai friends"; char *p1; 并修改你的代码: int main() { char p[] = "hai friends"; char *p0,*p1; p0 = p; p1 = p; while(*p0 !='\0') ++*p0++; pri ...
  • 第一步,从你称之为“re2”库的名称和部分来判断(这是非常着名的我不知道它;虽然它在Debian中,似乎没有任何东西需要它)是一个正则表达式库。 你已经在Python的re模块中有一个非常灵活的了。 其次, ctypes是本机库的不安全接口; 你需要完全正确地完成所有事情,这意味着理解底层类型系统,包括可以分配或释放内存以及由哪些例程执行的事情。 它的正常用例是包装具有C接口的库而不编写任何非Python代码。 在这种情况下,内存分配应该很容易,因为你只是返回一个bool并且不保留字符串引用。 但最重要的是 ...
  • 你必须将ch声明为int 。 否则,当出现字符ÿ时,文件的处理将停止。 char只能使用256个不同的值,这对于256个不同的符号+ EOF字符是不够的。 EOF是-1 ,当被视为int时相当于4,294,967,295 ,但当被视为char时它相当于255 。 如果您的输入文件包含字符ÿ (当被视为有signed时基本上为-1或255 ),则语句ch == EOF将变为true并且您的while循环将中断。 这与你的错误无关 ,但重要的是...... 如果程序崩溃,它会尝试读取/写入NULL指针,因为无法 ...
  • 如果在扫描阵列期间从未设置过mini ,则minimum函数可能会返回未初始化的值。 我不确定你的逻辑应该是什么,但也许你应该在你的函数顶部初始化mini = 0或做其他事情以防止这种情况发生。 您没有指定给定矩阵中应该包含的内容,但作为示例,所有零的矩阵将触发此行为。 Your function minimum could possibly return an uninitialized value, if mini was never set during your scan of the array. ...
  • 使用new而不是malloc在堆上创建C ++对象。 下列: head = (PNODE) malloc(sizeof(NODE)); 应该读 head = new NODE; malloc()在这里不起作用的原因是它不调用对象构造函数。 Use new rather than malloc to create C++ objects on the heap. The following: head = (PNODE) malloc(sizeof(NODE)); should read head = ...
  • 你必须传递指向fscanf值而不是值的指针(注意& temp- &temp->id和&temp->gpa的&符号; char[] -types lname和fname自动衰减为指针): while(fscanf(file1, "%s %s %d %f", temp->fname, temp->lname, &temp->id, &temp->gpa) != EOF) { You have to pass pointers to values instead of values to fscanf (not ...
  • 嗯,你确定段错是来自那个代码吗? 你调试过了吗? 我宁愿尝试这个: int sum_to_leaf(struct node* root,int sum) { if(root==NULL) { return sum; } else { sum=sum+root->data; int left_sum = sum_to_leaf(root->left, sum); int right_sum = sum_to_leaf(r ...
  • 当check_board 应该是一个struct数组时,它被声明为一个指针数组。 同样对于dummy和dummy_symbol ( dummy_symbol ,你根本不需要)。 如果你想要malloc一个符号,那么malloc一个符号,而不是一个符号的指针。 但你甚至不需要malloc :只需声明基于堆栈的变量: struct Player_symbols player_1_symbols; // no pointer, no malloc needed Your check_board is decla ...
  • 根据问题陈述, T可能高达100000.当T高于100时,以下语句 scanf("%d %d",&n[i],&m[i]); 产生未定义的行为,因为n和m都是100。 由于每个测试用例都可以单独处理,所以根本不需要n和m数组:用标量变量m和n替换它们,删除第一个for循环,并在第二个循环中调用scanf : int i,t,flag,j,x,k,m,n; scanf("%d",&t); for(x=1;x<=t;x++) { scanf("%d %d", &n, &m); ... } 注意 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)