Skip to content

toArray()

Evgheniy Kovaliov edited this page May 9, 2023 · 1 revision

toArray(ip)

Description

Method that allows you convert ip address to array of numbers (address' octets).
Ip address must be correct. (see validation)

Contract

Parameters:

  • ip: string — ip address to convert.

Return:

  • [number, number, number, number]
Exceptions

Invalide ip address!:

  • entered argument is not a correct ip address.
Usage
ipv4.toArray('123.123.123.123');  // [123, 123, 123, 123]
ipv4.toArray('0.0.0.0');          // [0, 0, 0, 0]
ipv4.toArray('255.255.255.255');  // [255, 255, 255, 255]
ipv4.toArray('1.2.3.4');          // [1, 2, 3, 4]
ipv4.toArray('0.0.0.1');          // [0, 0, 0, 1]

ipv4.toArray('111.222.-2.0');     // Error: Invalide ip address!
ipv4.toArray('256.256.256.256');  // Error: Invalide ip address!
ipv4.toArray('10.255.255');       // Error: Invalide ip address!
ipv4.toArray('ten.zero.one.one'); // Error: Invalide ip address!
ipv4.toArray('127.0.0.0.10');     // Error: Invalide ip address!
  • Is used in other methods.

MAIN PAGE

See all methods documentation:

For ip version 4

For ip version 6

Clone this wiki locally