“Pegue o último item em uma matriz JS” Respostas de código

JS Tome o último item na matriz

const heroes = ["Batman", "Superman", "Hulk"];
const lastHero = heroes.pop(); // Returns last elment of the Array
// lastHero = "Hulk"
Strange Starling

Obtenha o último item no JavaScript de Array

var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
Annoying Ant

JavaScript Tome o último elemento da matriz

let array = [1,2,3,4,5];
let lastElement = array.pop();

// array -> [1,2,3,4];
// lastElement = 5;
Nice Nightingale

Pegue o último item em uma matriz JS

function(code){
 	let lastItemArray = ''
  	console.log(code)
  	for(let i = 0; i < code.length; i++){
      if(i == code.length - 1)
      {
        lastItemArray = code[i]
      }
	}
  	return lastItemArray
}
console.log([1,2,3,4,5])
Wide-eyed Wolf

Respostas semelhantes a “Pegue o último item em uma matriz JS”

Perguntas semelhantes a “Pegue o último item em uma matriz JS”

Mais respostas relacionadas para “Pegue o último item em uma matriz JS” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código