Caution on Int8Array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
let t = crypto.getRandomValues(new Int8Array(3))
// Int8Array(3) [-15, -17, -90]

// t is not typeof Array
Array.isArray(t)
// false

// element in Int8Array must be type Int8
// method map returns array of same type as origin array
let _t = []
t.map(i => {
let _tmp = i.toString(16)
_t.push(_tmp)
return _tmp
})
// Int8Array(3) [0, -11, 0]
// _t: ['-f', '-11', '-5a']

t[0] = 'a'
// t: Int8Array(3) [0, -17, -90]

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×