JavaScript Uint8Array.map(…) unexpected behaviour

I tried to call .map on Uint8Array and got a surprise.

const tt = new Uint8Array(1);
tt[0] = 0xFF;

const ttt = tt.map(x => x.toString(2));

console.log(ttt[0]);
console.log(tt[0].toString(2));
Answer:1

That's because Uint8Array.map returns a Uint8Array. All the strings you return, get parsed as uint8s again ... and thus you get 199 (11111111 & (2 ** 8 - 1)).

You might wanna do:

 Array.from(tt).map(x => x.toString(2))
Answer:2

I have to populate a third select based on second. I'm trying like code below. As it is I'm feeding first select with all countries in DB. Second select is feeded based on first select. I need to ...

I have to populate a third select based on second. I'm trying like code below. As it is I'm feeding first select with all countries in DB. Second select is feeded based on first select. I need to ...

kindly assist me to know why when i call a function and pass a parameter using a string in its 'raw form' i get the right output but when i assign it to a variable first i get a different output. i ...

kindly assist me to know why when i call a function and pass a parameter using a string in its 'raw form' i get the right output but when i assign it to a variable first i get a different output. i ...

EDIT: I have to make this work on IE11 I have the following code: span.classList.add(span.textContent === '\ ' ? 'char' : 'spaceChar') It is working fine, but I would like to add 2 classes in case ...

EDIT: I have to make this work on IE11 I have the following code: span.classList.add(span.textContent === '\ ' ? 'char' : 'spaceChar') It is working fine, but I would like to add 2 classes in case ...

  1. javascript pass operator as parameter
  2. javascript pass operator to function
  3. javascript pass operator
  4. js pass operator as argument

I am facing problem to format the output as days/mon/years i.e ( 25/08/2019) when I add 5 days with the current date in momentjs. console.log( moment().add(5, 'days').calendar()); Output: Sunday ...

I am facing problem to format the output as days/mon/years i.e ( 25/08/2019) when I add 5 days with the current date in momentjs. console.log( moment().add(5, 'days').calendar()); Output: Sunday ...

  1. days current affairs
  2. days(current date) in db2
  3. days current cast
  4. days(current date)
  5. days(current timestamp)
  6. days current year
  7. how to calculate days with current date in excel
  8. how to add days with current date in java
  9. how to add days with current date in php
  10. how to add days with current date in jquery