• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Create a new array from an existing one

Create a new array from an existing one

Create a new array from an existing one

Create a new array from an existing one, or transform an array-like object (like a NodeList) into an array. Pass the array (or array-like object) to copy in as an argument.

var sandwiches = ['turkey', 'tuna', 'ham', 'pb&j'];
var sandwichesCopy = Array.from(sandwiches);

Source

https://vanillajstoolkit.com/reference/arrays/array-from/

Miscellaneous

Related Snippets:

  • Insert an element into the DOM after another one
  • Wrap an element around a given element
  • How to loop through arrays and array-like objects in JavaScript
  • Remove an element from the DOM

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers