Skip to content
Gallery
Coda Formulas to JavaScript
Share
Explore

icon picker
Coda Formulas to JavaScript

Search Formula Name:
Formulas
Not synced yet
Category
Coda Formula
Formula Documentation
JavaScript
Warning
Notes
Collections
8
Count(list...)
list.length

CountUnique(value...)
(new Set(value)).size

Find(needle, haystack)
haystack.indexOf(needle, startAt)

MaxBy(list, compareBy)
list.sort((a, b) =>
compareBy(a) > compareBy(b) ? 1 : -1)
[list.length + 1]

MinBy(list, compareBy)
list.sort((a, b) =>
compareBy(a) > compareBy(b) ? 1 : -1)
[0]

Slice(value, start)
value.slice(start, end)
End index non-inclusive.
Sort(dataset)
dataset.sort((a, b) =>
sortBy(a) > sortBy(b) ? 1 : -1)
JS sorts lexographically
Splice(value, start, deleteCount, insertValue...)
value.splice(start, deleteCount, insertValue)
To insert a list, use ...insertValue
Dates
32
Created(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
CurrentTimezone()
Not possible
Packs run on the server, and don’t have any information about the user looking at the doc.
Date(year, month, day)
new Date(year + "-" + month + "-" + day)

DateTime(year, month, day)
new Date(year + "-" + month + "-" + day)

DateTimeTruncate(dateOrTime, unit)
Needs library

DateToEpoch(date)
date.getTime()

Day(dateTime)
dateTime.getDate()
Time zone shifting
DocumentTimezone()
context.timezone

EndOfMonth(dateTime, monthOffset)
Needs library

EpochToDate(epochTime)
new Date(epochTime)

Hour(dateOrTime)
dateTime.getHours()
Time zone shifting
IsoWeekday(dateTime)
dateTime.getDay()

IsoWeekNumber(dateTime)
Needs library

Minute(dateOrTime)
dateTime.getMinutes()

Modified(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
Month(dateTime)
dateTime.getMonth()
Months start at 0.
MonthName(dateTime)
dateTime.toLocaleDateString("en", {
month: "long"
})
Time zone shifting
NetWorkingDays(startDate, endDate)
Needs library

Now()
new Date()

RelativeDate(dateTime, months)
dateTime = dateTime.setMonth(
dateTime.getMonth() + months)

Second(dateOrTime)
dateTime.getSeconds()

Time(hour, minute, second)
Needs library
JavaScript doesn’t have a native way to represent a pure time value.
TimeValue(time)
Needs library
JavaScript doesn’t have a native way to represent a pure time value.
ToDate(text)
Date.parse(text)

ToDateTime(datetime)
Date.parse(text)

Today()
let today = new Date();
today.setHours(0, 0, 0, 0);

ToTime(value)
Needs library
JavaScript doesn’t have a native way to represent a pure time value.
Weekday(dateTime)
dateTime.getDay()

WeekdayName(dateTime)
dateTime.toLocaleDateString("en", {
weekday: "long"
})

WeekNumber(dateTime)
Needs library

Workday(startDate, numWorkingDays)
Needs library

Year(dateTime)
dateTime.getFullYear()

Duration
9
Days(days)
Needs library

Duration()
Needs library

Hours(hours)
Needs library

Minutes(minutes)
Needs library

Seconds(seconds)
Needs library

ToDays(duration)
Needs library

ToHours(duration)
Needs library

ToMinutes(duration)
Needs library

ToSeconds(duration)
Needs library

Filters
7
AverageIf(list, expression)
let filtered = list.filter(num => expression);
let result = filtered.reduce((sum, num) => sum + num, 0) / filtered.length;

CountIf(list, expression)
list.filter(num => expression).length

Filter(list, expression)
list.filter(currentValue => expression)

IsFromTable(row, table)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
Lookup(table, column, match value)
Not possible
You can’t pass entire rows or tables into a Pack, so there is no equivalent.
Matches(value, control)
Too complex
The logic in the Matches() formula is complex, and there isn’t a simple equivalent in JavaScript.
SumIf(list, expression)
list.filter(num => expression)
.reduce((result, num) => result + num)

Logical
9
And(value...)
value1 && value2

False()
false

If(condition, ifTrue, ifFalse)
let result;
if (condition) {
result = ifTrue;
} else {
result = ifFalse;
}

IfBlank(value, ifBlank)
let result = value;
if (result == undefined) {
result = ifBlank;
}

Not(value)
!value

Or(value...)
value1 || value2 || value3

Switch(expression, value, result, arg...)
let result;
switch (expression) {
case value1:
result = result1;
break;
case value2:
result = result2;
break;
default:
result = defaultValue;
}

SwitchIf(condition, ifTrue, arg...)
let result;
if (condition1) {
result = ifTrue1;
} else if (condition2) {
result = ifTrue2;
} else {
result = defaultValue;
}

True()
true

Info
9
IsBlank(value)
value == undefined

IsDate(value)
value instanceof Date

IsLogical(value)
typeof value == "boolean"

IsNotBlank(value)
value != undefined

IsNotText(value)
typeof value != "string"

IsNumber(value)
typeof value == "number"

IsText(value)
typeof value == "string"

ToNumber(value)
parseFloat(value, base)

ToText(value)
value.toString()

Math
39
AbsoluteValue(number)
Math.abs(number)

Average(value...)
list.reduce((sum, num) => sum + num, 0) / list.length

BinomialCoefficient(n, k)
Needs library

Ceiling(value)
Math.ceil(value)

Even(value)
value % 2 == 0 ? value : value + 1

Exponent(value)
Math.exp(value)

Factorial(value)
Needs library

Floor(value)
Math.floor(value)

IsEven(value)
value % 2 == 0

IsOdd(value)
value % 2 == 1

Ln(number)
Math.log(number)

Log(number, base)
Math.log(number) / Math.log(base)

Log10(number)
Math.log10(number)

Max(value...)
Math.max(value1, value2)
Math.max(...list)

Median(value...)
Needs library

Min(value...)
Math.min(value1, value2)
Math.min(...list)

Mode(value...)
Needs library

Odd(value)
value % 2 == 1 ? value : value + 1

Percentile(dataset, percentile)
Needs library

PercentileRank(dataset, value)
Needs library

Pi()
Math.PI

Power(number, exponent)
Math.pow(number, exponent)

Product(value...)
value1 * value2

Quotient(dividend, divisor)
dividend / divisor

Random()
Math.random()

RandomInteger(low, high)
Math.floor(Math.random() * (high - low + 1) + low)

Rank(value, dataset)
Needs library

Remainder(dividend, divisor)
dividend % divisor

Round(number)
Math.round(number)

RoundDown(number)
Math.floor(number)

RoundTo(value, factor)
Needs library

RoundUp(number)
Math.ceil(number)

Sign(number)
number / Math.abs(number)

SquareRoot(number)
Math.sqrt(number)

StandardDeviation(value...)
Needs library

StandardDeviationPopulation(value...)
Needs library

Sum(value...)
value1 + value2

SumProduct(list1, list2)
let result = 0;
for (let i = 0; i < list1.length; i++) {
result += list1[i] * list2[i];
}

Truncate(number)
Needs library

Misc
3
ObjectLink(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
PageName(object)
Not possible

ParseCSV(csvString)
Needs library

Object
1
ParseJSON(jsonString)
JSON.parse(jsonString).path.path
Instead of using a path string, “dot” into the parsed object.
People
4