+ 1

Someone explain this please

Hello. Please can someone look at this code and explain to me what substring(0,2) means. Also I saw splice(0,2) does same thing. Please explain what substring and splice does. https://code.sololearn.com/WP9otHuIt2m9/?ref=app

21st Jul 2018, 10:15 PM
Emeruche Ikenna Cole
Emeruche Ikenna Cole - avatar
8 Respuestas
+ 2
splice or slice? splice add or remove array items and the syntax is.. array.splice(positionOfArrayToStartAdding/Removing, howManyItems, itemToAdd1, ...) slice and substring are basically the same. but slice starts from the end of a string
21st Jul 2018, 11:12 PM
Guillem Padilla
Guillem Padilla - avatar
+ 1
KrOW Thanks a lot. But is there now any major difference between the two? Or they actually do dame thing?
21st Jul 2018, 11:05 PM
Emeruche Ikenna Cole
Emeruche Ikenna Cole - avatar
+ 1
Hi, Substring gets a part of an string. string.substring(fromPosition, toPosition) *toPosition: up to, but not including* string index starts at position 0, so substring(0, 2) extracts the two first characters of the string
21st Jul 2018, 11:06 PM
Guillem Padilla
Guillem Padilla - avatar
+ 1
Hi Guillem Padilla What's the difference between it and splice
21st Jul 2018, 11:07 PM
Emeruche Ikenna Cole
Emeruche Ikenna Cole - avatar
0
A difference its that slice accept negative numbers, substring dont
21st Jul 2018, 11:17 PM
KrOW
KrOW - avatar
0
Guillem Padilla Sorry to bother. But pls an example would be nice. Can you write a code implementing splice? Thanks
22nd Jul 2018, 6:42 AM
Emeruche Ikenna Cole
Emeruche Ikenna Cole - avatar
0
If you see on links that i have posted, you will find examples also
22nd Jul 2018, 7:27 AM
KrOW
KrOW - avatar