swati-jagtap / javascript-practice

0 stars 0 forks source link

//9.1.16--Declare a function called getStringLists which takes an array as a parameter and then returns an array only with string items. #111

Closed swati-jagtap closed 3 years ago

swati-jagtap commented 3 years ago

const countries = ['Finland', 'Sweden', 'Denmark', 'Norway', 'IceLand']
const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
const products = [
  { product: 'banana', price: 3 },
  { product: 'mango', price: 6 },
  { product: 'potato', price: ' ' },
  { product: 'avocado', price: 8 },
  { product: 'coffee', price: 10 },
  { product: 'tea', price: '' },
]
//9.1.16--Declare a function called getStringLists which takes an array as a parameter and then returns an array only with string items.
function getStringLists(arr){

 const stringArray=arr.filter((a)=>typeof(a)=="string")
 return stringArray;

}
console.log(getStringLists([1,4,"jdfojf","67",6,"df",9]))

image


function getStringLists(arr){

 const stringArray=arr.filter((a)=>typeof(a)==string)
 return stringArray;

}
console.log(getStringLists([1,4,"jdfojf","67",6,"df",9]))

image