DEV Community

loading...

Discussion on: JavaScript Quiz Part 2

Collapse
navi profile image
Navneet Sahota

1.How to reverse a String Using Reduce Method.

function reverseString(str) {
  const arr = str.split('');
  return arr.reduce((acc, val) => val + acc,"");
}

2.What is the difference between slice and splice?

  • Slice method is used to get some portion of the existing array/string.
  • Splice method actually mutates the existing array and can add or remove items from the array.

3.How to convert an object into a string?

  • Not Sure what you want as output. Others have explained it well though.