Perhaps it is simpler to extend javascript's native Array, so that there is no need for keeping around an extra Vector.arr property. Here is a simple implementation called for learning purposes that boils down to this, in modern JS:

class Vector extends Array {
  // example methods
  add(other) {
    return this.map((e, i) => e + other[i]);
  }
}

// example usage
let v = new Vector(1, 2, 3);
console.log(v.add(v));

This class inherits Array's constructor. Note passing in a single value creates an empty Array of that length and not a length 1 Array. Vector would require a super call in the constructor to inherit exotic Array behavior, such as having a special length property, but this shouldn't be needed for a math vector of fixed length. You can include fancier constructor behavior here, such as being able to construct from an Array as input.

Answer from qwr on Stack Overflow
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › vectors in javascript
Vectors in JavaScript | Learn How a vector can be created in JavaScript?
March 27, 2023 - Guide to Vectors in JavaScript. Here we discuss the introduction, various examples and why vectors are used in JavaScript respectively.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
npm
npmjs.com › package › @js-basics › vector
js-basics/vector
This library gives javascript coders a way to handle operators with a single statement () => aVec * bVec - dVec. The calculation can be combined with numbers () => aVec * bVec * 4 - dVec - 1.5. Vector objects can be create with number new Vector(5, ...
      » npm install @js-basics/vector
    
Published   Jul 04, 2025
Version   2.2.5
🌐
GitHub
github.com › tronkko › js-vector
GitHub - tronkko/js-vector: Vector and matrix math on JavaScript
Vector and matrix math on JavaScript. Contribute to tronkko/js-vector development by creating an account on GitHub.
Starred by 14 users
Forked by 3 users
Languages   JavaScript 99.7% | HTML 0.3% | JavaScript 99.7% | HTML 0.3%
🌐
Victorjs
victorjs.org
Victor.js - 2D Vectors for JavaScript
Copies the X component of another vector in to itself.
🌐
GitHub
gist.github.com › jjgrainger › 808640fcb5764cf92c3cad960682c677
A simple Vector class in javascript · GitHub
Clone this repository at <script src="https://gist.github.com/jjgrainger/808640fcb5764cf92c3cad960682c677.js"></script> Save jjgrainger/808640fcb5764cf92c3cad960682c677 to your computer and use it in GitHub Desktop. ... This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ... // dot product of two vectors Vector.prototype.dotProduct = function(v2) { return this.x * v2.x + this.y *v2.y; } // normalize a given vector Vector.prototype.normalize = function(){ return new Vector(this.x/(Math.sqrt(this.x * this.x + this.y * this.y)), this.y/(Math.sqrt(this.x * this.x + this.y * this.y))); }
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript vector
How to Add Vector Class in JavaScript | Delft Stack
February 2, 2024 - This article will teach you how to add vectors in JavaScript using a for loop, ES6 Map, ES6 class, and extending the native Array class.
Find elsewhere
🌐
Paper.js
paperjs.org › tutorials › geometry › vector-geometry
Paper.js — Vector Geometry
This script is developed step by step in the Working with Mouse Vectors tutorial, along with explanations about each line of code.
🌐
Vectorjs
vectorjs.org › tutorials
Vector.js
Vector is an open source javascript library for creating interactive graphics. View the repository, run the tests, or meet the team. Examples Tutorials
🌐
Evanw
evanw.github.io › lightgl.js › docs › vector.html
vector.js
Provides a simple 3D vector class. Vector operations can be done using member functions, which return new vectors, or static functions, which reuse existing vectors to avoid generating garbage · The methods add(), subtract(), multiply(), and divide() can all take either a vector or a number ...
🌐
Starbeamrainbowlabs
starbeamrainbowlabs.com › blog › article.php
Vector.js: A simple vector class in ES6 | Stardust | Starbeamrainbowlabs
February 1, 2018 - var v = new Vector(100, 100), // Create a new vector for the point (100, 100) v2 = new Vector(300, 400); // Vector for the point (300, 400) // Clone v and subtracts v2 from it, putting the result into v3.
🌐
Radzion
radzion.com › blog › linear-algebra › vectors
Vectors and Vectors Operations With JavaScript - Radzion.com
May 3, 2019 - If we take the dot product of two normalized vectors and the result is equal to one it means that they have the same direction. To compare two float numbers, we will use the areEqual function. have-same-direction-with.js · const EPSILON = 0.00000001 const areEqual = (one, other, epsilon = EPSILON) => Math.abs(one - other) < epsilon class Vector { constructor(...components) { this.components = components } // ...
🌐
Duke University
sites.math.duke.edu › ~jdr › linalg_js › doc › vector.js.html
vector.js
Instead use the convenience routine * {@link Vector.create}. * * @example * Vector.create(1, 2, 3).toString(1); // "[1.0 2.0 3.0]" * * @extends Array */ class Vector extends Array { /** * @summary * Create a Vector with the given entries.
🌐
GeeksforGeeks
geeksforgeeks.org › p5-js-createvector-function
p5.js createVector() function | GeeksforGeeks
August 23, 2023 - function setup() { // Create a Canvas createCanvas(500, 550); } function draw() { // Vector initialisation // using createVector t1 = createVector(10, 40); t2 = createVector(41, 50); // Set background color background(200); // Set stroke weight strokeWeight(2); // Fill yellow fill('yellow'); // ellipse using vector ellipse(t1.x*millis() / 1000 * 20, t1.y, t2.x+100, t2.y+100); } ... The createVideo() function is used to create a video element in the DOM. The video is created as a p5.MediaElement, which has methods for controlling the media and its playback. Syntax: createVideo(src, callback) Parameters: This function accepts two parameters as mentioned above and described below ... The createA() function in p5.js is used to create an anchor element in the DOM (Document Object Model) for creating a hyperlink.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-work-with-vectors-in-mathjs
How to Work with Vectors in MathJS? - GeeksforGeeks
July 23, 2025 - JS Tutorial · Web Tutorial · A to Z Guide · Projects · OOP · DOM · Set · Map · Math · Number · Boolean · Exercise · Last Updated : 23 Jul, 2025 · Vectors are fundamental components in mathematics and physics, representing quantities that have both magnitude and direction.
🌐
GitHub
github.com › basics › vector
GitHub - basics/vector: This library provides 3D Vector in js including arithmetic operator overloading (+ - * / % **). · GitHub
This library gives javascript coders a way to handle operators with a single statement () => aVec * bVec - dVec. The calculation can be combined with numbers () => aVec * bVec * 4 - dVec - 1.5. Vector objects can be create with number new Vector(5, ...
Starred by 14 users
Forked by 3 users
Languages   JavaScript 99.6% | Shell 0.4%
🌐
GitHub
github.com › vector-js › vector
GitHub - vector-js/vector: A javascript library for creating interactive graphics. · GitHub
May 7, 2024 - Vector.js is a Javascript library for creating interactive graphics on the web. The library uses the existing web standards: HTML, SVG, and CSS and has no dependencies.
Starred by 199 users
Forked by 19 users
Languages   JavaScript 68.1% | TypeScript 30.3%
🌐
Brm
brm.io › matter-js › docs › classes › Vector.html
Matter.Vector Module - Matter.js Physics Engine API Docs - matter-js 0.20.0
src/geometry/Vector.js:40 · Usages · Examples · (vector) → Number · Returns the magnitude (length) of a vector (therefore saving a sqrt operation). vector Vector · Number · The squared magnitude of the vector · src/geometry/Vector.js:50 · Usages · Examples ·