Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React native typescript number 0 read as NaN

$
0
0

I am trying to map an array and to use its values or keys as data for my return in React Native (Android).Can anyone explain why the value 0 is being read as NaN?I have noticed the same issue when using an typescript enum.

I am using:typescript v.4.7.4, RN 0.69.2 and react 18

Simple code example with console output:

const R = [...Array(4).keys()];R.map((_i, key) => {  console.log(_i, key);}); Output: NaN NaN  // value 0 is interpreted as NaN ???1 12 23 3

This only seems to happen when the value is assessed directly via console.log or the VSCode inspector in debug mode. Whenever I use à template string the value is correctly displayed.

R.forEach(i => {  console.log(`value is : ${i} is ${typeof i}`);  console.log(i);});Output: value is : 0 is numberNaNvalue is : 1 is number1value is : 2 is number2value is : 3 is number3

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>