You're viewing the legacy docs. They are deprecated as of May 18, 2016.
These docs are for version 2.4.2 and below of the Javascript SDK. Go to our current docs, or see our Web migration guide.

Version 2.4.2Changelog

DataSnapshot.exportVal()

The exportVal() method is similar to val(), except priority information is included (if available), making it suitable for backing up your data.

The export format differs depending on what type of data is being read. In the case of primitive values (a string, number, or boolean) without a priority, a primitive value is returned:

ref.set("hello", function(error) {
  ref.once("value", function(snapshot) {
    var data = snapshot.exportVal();
    // data === "hello"
  });
});

In the case of primitive values (a string, number, or boolean) with a priority, the value is wrapped in an object with .value and .priority properties:

ref.setWithPriority("hello", 500, function(error) {
  ref.once("value", function(snapshot) {
    var data = snapshot.exportVal();
    // data is { ".value": "hello", ".priority": 500 }
    // data[".value"] === "hello"
    // data[".priority"] ===  500
  });
});

In the case of reading data that is a JavaScript object without a priority, a JavaScript object is returned:

ref.setWithPriority({ name: "Fred", age: 53 }, function(error) {
  ref.once("value", function(snapshot) {
    var data = snapshot.exportVal();
    // data is { "name": "Fred", "age": 53 }
    // data.name === "Fred"
    // data.age === 53
  });
});

In the case of JavaScript objects with a priority, a JavaScript object with .priority entries for all nodes with priorities is returned:

ref.setWithPriority({ name: "Fred", age: 53 }, 500, function(error) {
  ref.once("value", function(snapshot) {
    var data = snapshot.exportVal();
    // data is { "name": "Fred", "age": 53, ".priority": 500 }
    // data.name === "Fred"
    // data.age === 53
    // data[".priority"] === 500
  });
});